mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 02:08:27 +01:00
SubServers 2 Beta 3
This commit is contained in:
parent
82b9d9b2d0
commit
d6c9729304
2
.gitignore
vendored
2
.gitignore
vendored
@ -26,9 +26,7 @@ crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
|
||||
# Hide Unfinished Project Files
|
||||
/Artifacts/SubServers.Client.Bukkit.jar
|
||||
/Artifacts/SubServers.Host.jar
|
||||
/SubServers.Client/Bukkit/
|
||||
/SubServers.Host/
|
||||
|
||||
# Hide Others
|
||||
|
Binary file not shown.
BIN
Artifacts/SubServers.Client.Bukkit.jar
Normal file
BIN
Artifacts/SubServers.Client.Bukkit.jar
Normal file
Binary file not shown.
@ -8,9 +8,10 @@ SubServers 2 is a rewrite of SubServers, the Server Management Plugin.
|
||||
* The Proxy hosts the Servers (instead of the Servers hosting the Proxy)
|
||||
* Just about everything your players will see either looks like BungeeCord or is Customizable
|
||||
|
||||
## How to install the Beta Releases
|
||||
## How to install/update the Beta Releases
|
||||
1. Download BungeeCord ([Link](https://www.spigotmc.org/link-forums/bungeecord.28/))
|
||||
2. Download your favorite commit of SubServers.Bungee ([Click Here](https://github.com/ME1312/SubServers-2/tree/master/Artifacts) for the latest commit)
|
||||
3. Put them both in a folder together. It should now look like this:
|
||||
![Example Folder](https://s30.postimg.org/qhcx95jep/Screen_Shot_2016_12_15_at_4_30_15_PM.png)
|
||||
4. You can now launch SubServers via your terminal: `java -jar SubServers.Bungee.jar`
|
||||
4. If you are updating, make sure to update the files in `~/SubServers`, they wont reset themselves.
|
||||
5. You can now launch SubServers via your terminal: `java -jar SubServers.Bungee.jar`
|
@ -0,0 +1,67 @@
|
||||
package net.ME1312.SubServers.Proxy.Event;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Host.Server;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.NamedContainer;
|
||||
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.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private SubServer server;
|
||||
private List<NamedContainer<String, ?>> changes;
|
||||
|
||||
/**
|
||||
* Server Edit Event
|
||||
*
|
||||
* @param player Player Starting Server
|
||||
* @param server Server Being Changed
|
||||
* @param change Pending Changes
|
||||
*/
|
||||
public SubEditServerEvent(UUID player, SubServer server, NamedContainer<String, ?>... change) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.changes = Arrays.asList(change);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server to be Added
|
||||
* @return The Server to be Added
|
||||
*/
|
||||
public Server getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
/**
|
||||
* Gets the Changes to made by this Edit
|
||||
* @return Pending Changes
|
||||
*/
|
||||
public List<NamedContainer<String, ?>> getChanges() {
|
||||
return changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Cancelled Status
|
||||
* @return Cancelled Status
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Cancelled Status
|
||||
*/
|
||||
public void setCancelled(boolean value) {
|
||||
cancelled = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
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 SubRemoveServerEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private Host host;
|
||||
private Server server;
|
||||
|
||||
/**
|
||||
* Server Add Event
|
||||
*
|
||||
* @param player Player Adding Server
|
||||
* @param server Server Starting
|
||||
*/
|
||||
public SubRemoveServerEvent(UUID player, Host host, Server server) {
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server to be Added
|
||||
* @return The Server to be Added
|
||||
*/
|
||||
public Server getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the Host of the Server
|
||||
*
|
||||
* @return The Host of the Server or null if isn't a SubServer
|
||||
*/
|
||||
public Host getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
/**
|
||||
* Gets the Cancelled Status
|
||||
* @return Cancelled Status
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Cancelled Status
|
||||
*/
|
||||
public void setCancelled(boolean value) {
|
||||
cancelled = value;
|
||||
}
|
||||
}
|
@ -76,6 +76,7 @@ public abstract class Host {
|
||||
* Starts the Servers Specified
|
||||
*
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public int start(String... servers) {
|
||||
return start(null, servers);
|
||||
@ -86,6 +87,7 @@ public abstract class Host {
|
||||
*
|
||||
* @param player Player who started
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract int start(UUID player, String... servers);
|
||||
|
||||
@ -93,6 +95,7 @@ public abstract class Host {
|
||||
* Stops the Servers Specified
|
||||
*
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public int stop(String... servers) {
|
||||
return stop(null, servers);
|
||||
@ -103,6 +106,7 @@ public abstract class Host {
|
||||
*
|
||||
* @param player Player who started
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract int stop(UUID player, String... servers);
|
||||
|
||||
@ -110,6 +114,7 @@ public abstract class Host {
|
||||
* Terminates the Servers Specified
|
||||
*
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public int terminate(String... servers) {
|
||||
return terminate(null, servers);
|
||||
@ -120,6 +125,7 @@ public abstract class Host {
|
||||
*
|
||||
* @param player Player who started
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract int terminate(UUID player, String... servers);
|
||||
|
||||
@ -128,6 +134,7 @@ public abstract class Host {
|
||||
*
|
||||
* @param command Command to send
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public int command(String command, String... servers) {
|
||||
return command(null, command, servers);
|
||||
@ -139,15 +146,28 @@ public abstract class Host {
|
||||
* @param player Player who started
|
||||
* @param command Command to send
|
||||
* @param servers Servers
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract int command(UUID player, String command, String... servers);
|
||||
|
||||
/**
|
||||
* Applies edits to the Host
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param change Change(s) to be applied
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean edit(NamedContainer<String, ?>... change);
|
||||
public abstract int edit(UUID player, NamedContainer<String, ?>... change);
|
||||
|
||||
/**
|
||||
* Applies edits to the SubServer
|
||||
*
|
||||
* @param change Change(s) to be applied
|
||||
* @return Success Status
|
||||
*/
|
||||
public int edit(NamedContainer<String, ?>... change) {
|
||||
return edit(null, change);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubCreator Instance for this Host
|
||||
@ -219,14 +239,37 @@ public abstract class Host {
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @throws InterruptedException
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract void removeSubServer(String name) throws InterruptedException;
|
||||
public boolean removeSubServer(String name) throws InterruptedException {
|
||||
return removeSubServer(null, name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
* @throws InterruptedException
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean removeSubServer(UUID player, String name) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public abstract void forceRemoveSubServer(String name);
|
||||
public boolean forceRemoveSubServer(String name) {
|
||||
return forceRemoveSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public abstract boolean forceRemoveSubServer(UUID player, String name);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ME1312.SubServers.Proxy.Host.Internal;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Proxy.Event.SubRemoveServerEvent;
|
||||
import net.ME1312.SubServers.Proxy.Host.Executable;
|
||||
import net.ME1312.SubServers.Proxy.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Proxy.Host.Host;
|
||||
@ -16,7 +17,7 @@ import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class InternalHost extends Host {
|
||||
private HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
@ -102,13 +103,14 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean edit(NamedContainer<String, ?>... changes) {
|
||||
public int edit(UUID player, NamedContainer<String, ?>... changes) {
|
||||
int i = 0;
|
||||
for (NamedContainer<String, ?> change : changes) {
|
||||
switch (change.name().toLowerCase()) {
|
||||
// TODO SubEditor
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,19 +143,29 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSubServer(String name) throws InterruptedException {
|
||||
if (getSubServer(name).isRunning()) {
|
||||
getSubServer(name).stop();
|
||||
getSubServer(name).waitFor();
|
||||
}
|
||||
servers.remove(name.toLowerCase());
|
||||
public boolean removeSubServer(UUID player, String name) throws InterruptedException {
|
||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(name));
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
if (getSubServer(name).isRunning()) {
|
||||
getSubServer(name).stop();
|
||||
getSubServer(name).waitFor();
|
||||
}
|
||||
servers.remove(name.toLowerCase());
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceRemoveSubServer(String name) {
|
||||
if (getSubServer(name).isRunning()) {
|
||||
getSubServer(name).terminate();
|
||||
}
|
||||
servers.remove(name.toLowerCase());
|
||||
public boolean forceRemoveSubServer(UUID player, String name) {
|
||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(name));
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
if (getSubServer(name).isRunning()) {
|
||||
getSubServer(name).terminate();
|
||||
}
|
||||
servers.remove(name.toLowerCase());
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package net.ME1312.SubServers.Proxy.Host.Internal;
|
||||
|
||||
import net.ME1312.SubServers.Proxy.Event.SubSendCommandEvent;
|
||||
import net.ME1312.SubServers.Proxy.Event.SubStartEvent;
|
||||
import net.ME1312.SubServers.Proxy.Event.SubStopEvent;
|
||||
import net.ME1312.SubServers.Proxy.Event.SubStoppedEvent;
|
||||
import net.ME1312.SubServers.Proxy.Event.*;
|
||||
import net.ME1312.SubServers.Proxy.Host.Executable;
|
||||
import net.ME1312.SubServers.Proxy.Library.Container;
|
||||
import net.ME1312.SubServers.Proxy.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Proxy.Host.Host;
|
||||
import net.ME1312.SubServers.Proxy.Host.SubServer;
|
||||
import net.ME1312.SubServers.Proxy.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Proxy.SubPlugin;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@ -19,12 +17,14 @@ import java.util.UUID;
|
||||
|
||||
public class InternalSubServer extends SubServer {
|
||||
private InternalHost host;
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private Container<Boolean> log;
|
||||
private File directory;
|
||||
private Executable executable;
|
||||
private String stopcmd;
|
||||
private Process process;
|
||||
private Thread thread;
|
||||
private BufferedWriter command;
|
||||
private boolean restart;
|
||||
private boolean allowrestart;
|
||||
@ -33,12 +33,14 @@ public class InternalSubServer extends SubServer {
|
||||
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.name = name;
|
||||
this.enabled = enabled;
|
||||
this.log = new Container<Boolean>(log);
|
||||
this.directory = new File(host.getDirectory(), directory);
|
||||
this.executable = executable;
|
||||
this.stopcmd = stopcmd;
|
||||
this.process = null;
|
||||
this.thread = null;
|
||||
this.command = null;
|
||||
this.restart = restart;
|
||||
this.temporary = temporary;
|
||||
@ -47,7 +49,7 @@ public class InternalSubServer extends SubServer {
|
||||
}
|
||||
|
||||
private void run() {
|
||||
new Thread(() -> {
|
||||
(thread = new Thread(() -> {
|
||||
allowrestart = true;
|
||||
try {
|
||||
process = Runtime.getRuntime().exec(executable.toString(), null, directory);
|
||||
@ -88,7 +90,7 @@ public class InternalSubServer extends SubServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
})).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,22 +159,193 @@ public class InternalSubServer extends SubServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean edit(NamedContainer<String, ?>... changes) {
|
||||
for (NamedContainer<String, ?> change : changes) {
|
||||
switch (change.name().toLowerCase()) {
|
||||
// TODO SubEditor
|
||||
public int edit(UUID player, NamedContainer<String, ?>... changes) {
|
||||
int i = 0;
|
||||
SubEditServerEvent eEvent = new SubEditServerEvent(player, this, changes);
|
||||
host.plugin.getPluginManager().callEvent(eEvent);
|
||||
if (!eEvent.isCancelled()) {
|
||||
for (NamedContainer<String, ?> change : changes) {
|
||||
try {
|
||||
boolean running = isRunning();
|
||||
switch (change.name().toLowerCase()) {
|
||||
case "host":
|
||||
if (change.get() instanceof String) {
|
||||
InternalHost oldhost = host;
|
||||
Host newhost = host.plugin.hosts.get(((String) change.get()).toLowerCase());
|
||||
if (newhost != null) {
|
||||
if (running) allowrestart = false;
|
||||
if (host.removeSubServer(player, getName())) {
|
||||
if (newhost.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), directory.getPath(), executable, getStopCommand(), running, willAutoRestart(), isHidden(), isRestricted(), isTemporary()) != null) {
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Host", newhost.getName());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
oldhost.servers.put(getName().toLowerCase(), this);
|
||||
if (running) start(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
if (change.get() instanceof String) {
|
||||
host.servers.remove(getName().toLowerCase());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").set((String) change.get(), host.plugin.config.get().getSection("Servers").getSection(getName()));
|
||||
host.plugin.config.get().getSection("Servers").remove(getName());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
name = (String) change.get();
|
||||
host.servers.put(((String) change.get()).toLowerCase(), this);
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "enabled":
|
||||
if (change.get() instanceof Boolean) {
|
||||
setEnabled((Boolean) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Enabled", isEnabled());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "log":
|
||||
if (change.get() instanceof Boolean) {
|
||||
setLogging((Boolean) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Log", isLogging());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "dir":
|
||||
if (change.get() instanceof String) {
|
||||
directory = new File((String) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Directory", directory.getPath());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
} else if (change.get() instanceof File) {
|
||||
directory = (File) change.get();
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Directory", directory.getPath());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "exec":
|
||||
if (change.get() instanceof String) {
|
||||
executable = new Executable((String) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", executable.toString());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
} else if (change.get() instanceof Executable) {
|
||||
executable = (Executable) change.get();
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", executable.toString());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "running":
|
||||
if (change.get() instanceof Boolean) {
|
||||
if (running) {
|
||||
if (!((Boolean) change.get())) stop(player);
|
||||
} else {
|
||||
if (((Boolean) change.get())) start(player);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "stop-cmd":
|
||||
if (change.get() instanceof String) {
|
||||
setStopCommand((String) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Command", getStopCommand());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "auto-run":
|
||||
if (change.get() instanceof Boolean) {
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Run-On-Launch", change.get());
|
||||
host.plugin.config.save();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "auto-restart":
|
||||
if (change.get() instanceof Boolean) {
|
||||
setAutoRestart((Boolean) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Auto-Restart", willAutoRestart());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "restricted":
|
||||
if (change.get() instanceof Boolean) {
|
||||
setRestricted((Boolean) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Restricted", isRestricted());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "hidden":
|
||||
if (change.get() instanceof Boolean) {
|
||||
setHidden((Boolean) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Hidden", isHidden());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case "motd":
|
||||
if (change.get() instanceof String) {
|
||||
setMotd((String) change.get());
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").getSection(getName()).set("Motd", getMotd());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitFor() throws InterruptedException {
|
||||
if (isRunning()) {
|
||||
process.waitFor();
|
||||
while (thread != null && thread.isAlive()) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return process != null && process.isAlive();
|
||||
|
@ -15,10 +15,16 @@ import java.net.InetSocketAddress;
|
||||
*/
|
||||
public class Server extends BungeeServerInfo implements ClientHandler {
|
||||
private Client client = null;
|
||||
private String motd;
|
||||
private boolean restricted;
|
||||
private boolean hidden;
|
||||
|
||||
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);
|
||||
this.motd = motd;
|
||||
this.restricted = restricted;
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,4 +41,60 @@ public class Server extends BungeeServerInfo implements ClientHandler {
|
||||
this.client = null;
|
||||
} else throw new IllegalStateException("A SubData Client is already linked to Server: " + getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* If the server is hidden from players
|
||||
*
|
||||
* @return Hidden Status
|
||||
*/
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setHidden(boolean value) {
|
||||
this.hidden = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MOTD of the Server
|
||||
*
|
||||
* @return Server MOTD
|
||||
*/
|
||||
@Override
|
||||
public String getMotd() {
|
||||
return motd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setMotd(String value) {
|
||||
this.motd = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the Server is Restricted
|
||||
*
|
||||
* @return Restricted Status
|
||||
*/
|
||||
@Override
|
||||
public boolean isRestricted() {
|
||||
return restricted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setRestricted(boolean value) {
|
||||
this.restricted = value;
|
||||
}
|
||||
}
|
||||
|
@ -100,10 +100,21 @@ public abstract class SubServer extends Server {
|
||||
/**
|
||||
* Applies edits to the SubServer
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param change Change(s) to be applied
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean edit(NamedContainer<String, ?>... change);
|
||||
public abstract int edit(UUID player, NamedContainer<String, ?>... change);
|
||||
|
||||
/**
|
||||
* Applies edits to the SubServer
|
||||
*
|
||||
* @param change Change(s) to be applied
|
||||
* @return Success Status
|
||||
*/
|
||||
public int edit(NamedContainer<String, ?>... change) {
|
||||
return edit(null, change);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the Server to Stop
|
||||
|
@ -26,7 +26,7 @@ if [ $2 == bukkit ] || [ $2 == spigot ]
|
||||
else
|
||||
echo ERROR: Failed Downloading Buildtools. Is SpigotMC.org down?
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 3
|
||||
fi
|
||||
if [ -d "Buildtools" ]
|
||||
then
|
||||
@ -62,7 +62,7 @@ if [ $2 == bukkit ] || [ $2 == spigot ]
|
||||
rm -Rf BuildTools.jar
|
||||
rm -Rf Buildtools
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
if [ $2 == "vanilla" ]; then
|
||||
@ -76,7 +76,7 @@ else
|
||||
curl -o Buildtools/Vanilla/minecraft_server.$1.jar https://s3.amazonaws.com/Minecraft.Download/versions/$1/minecraft_server.$1.jar; retvald=$?
|
||||
if [ $retvald -eq 0 ]; then
|
||||
echo Downloading Vanilla Patches...
|
||||
curl -o Buildtools/Vanilla/bungee-patch.jar http://minecraft.me1312.net/lib/subservers/vanilla-bungee-patch.1.2.jar; retvale=$?
|
||||
curl -o Buildtools/Vanilla/bungee-patch.jar https://raw.githubusercontent.com/ME1312/SubServers-2/master/SubServers.Bungee/Vanilla-Patch.jar; retvale=$?
|
||||
if [ $retvale -eq 0 ]; then
|
||||
echo Patching Vanilla for BungeeCord Support
|
||||
cd Buildtools/Vanilla
|
||||
@ -96,19 +96,19 @@ else
|
||||
echo ERROR: Failed Applying Patch.
|
||||
rm -Rf Buildtools
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 5
|
||||
fi
|
||||
else
|
||||
echo ERROR: Failed Downloading Patch. Is Dropbox.com down?
|
||||
echo ERROR: Failed Downloading Patch. Is Github.com down?
|
||||
rm -Rf Buildtools
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
echo ERROR: Failed Downloading Jarfile. Is Minecraft.net down?
|
||||
rm -Rf Buildtools
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 3
|
||||
fi
|
||||
else
|
||||
if [ $2 == "sponge" ]; then
|
||||
@ -137,20 +137,21 @@ else
|
||||
rm -Rf forge-${version[0]}-installer.jar.log
|
||||
rm -Rf forge-${version[0]}-universal.jar
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 5
|
||||
fi
|
||||
else
|
||||
echo ERROR: Failed Installing Forge.
|
||||
rm -Rf forge-${version[0]}-installer.jar
|
||||
rm -Rf forge-${version[0]}-installer.jar.log
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
echo ERROR: Failed Downloading Jarfile. Is MinecraftForge.net down?
|
||||
rm -Rf build-subserver.sh
|
||||
exit 1
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
exit 2
|
@ -9,9 +9,10 @@ Lang:
|
||||
'Interface.Generic.Downloading.Title-Color': '&b'
|
||||
'Interface.Generic.Downloading.Title-Color-Alt': '&3'
|
||||
'Interface.Generic.Downloading.Response': '&eWaiting for response'
|
||||
'Interface.Generic.Invalid-Permission': '&4You need &n$str$'
|
||||
'Interface.Host-Menu.Title': 'Host Menu'
|
||||
'Interface.Host-Menu.Host-Disabled': '&4Disabled'
|
||||
'Interface.Host-Menu.Host-Server-Count': '&9$int$ Servers'
|
||||
'Interface.Host-Menu.Host-Server-Count': '&9$int$ Server(s)'
|
||||
'Interface.Host-Menu.No-Hosts': '&c&oThere are No Hosts'
|
||||
'Interface.Host-Menu.SubServer-Menu': '&a&lSubServer Menu'
|
||||
'Interface.Host-Admin.Title': 'Host/$str$'
|
||||
@ -53,7 +54,7 @@ Lang:
|
||||
'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': '&2$int$ Players Online'
|
||||
'Interface.SubServer-Menu.SubServer-Player-Count': '&2$int$ Player(s) Online'
|
||||
'Interface.SubServer-Menu.SubServer-Temporary': '&9Temporary'
|
||||
'Interface.SubServer-Menu.SubServer-Offline': '&6Offline'
|
||||
'Interface.SubServer-Menu.SubServer-Disabled': '&4Disabled'
|
||||
|
@ -48,6 +48,7 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
info.put("name", server.getName());
|
||||
info.put("address", server.getAddress().toString());
|
||||
info.put("restricted", server.isRestricted());
|
||||
info.put("hidden", server.isHidden());
|
||||
info.put("motd", server.getMotd());
|
||||
info.put("subdata", server.getSubDataClient() == null);
|
||||
|
||||
|
@ -111,6 +111,7 @@ public class PacketOutRunEvent implements Listener, PacketOut {
|
||||
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("force", event.isForced());
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
@ -125,4 +126,18 @@ public class PacketOutRunEvent implements Listener, PacketOut {
|
||||
if (server.getSubDataClient() != null) server.getSubDataClient().sendPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void event(SubRemoveServerEvent 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -151,8 +151,7 @@ public final class SubCommand extends Command {
|
||||
i++;
|
||||
str = str + " " + args[i];
|
||||
}
|
||||
System.out.println("/subserver" + str);
|
||||
((ProxiedPlayer) sender).chat("/subserver" + str);
|
||||
((ProxiedPlayer) sender).chat("/subservers" + str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
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(2);
|
||||
protected Version bversion = new Version(3);
|
||||
|
||||
protected boolean running = false;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
|
7
SubServers.Client/Bukkit/src/config.yml
Normal file
7
SubServers.Client/Bukkit/src/config.yml
Normal file
@ -0,0 +1,7 @@
|
||||
Settings:
|
||||
Version: '2.11.0a+'
|
||||
Use-Title-Messages: true
|
||||
SubData:
|
||||
Name: 'Server_1'
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'password123'
|
@ -0,0 +1,55 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubAddServerEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private String host;
|
||||
private String server;
|
||||
|
||||
/**
|
||||
* Server Add Event
|
||||
*
|
||||
* @param player Player Adding Server
|
||||
* @param server Server Starting
|
||||
*/
|
||||
public SubAddServerEvent(UUID player, String host, String server) {
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server to be Added
|
||||
* @return The Server to be Added
|
||||
*/
|
||||
public String getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the Host of the Server
|
||||
*
|
||||
* @return The Host of the Server or null if isn't a SubServer
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCreateServer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubCreateEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private String host;
|
||||
private String name;
|
||||
private PacketCreateServer.ServerType type;
|
||||
private Version version;
|
||||
private int memory;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Server Create Event
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param host Potential Host
|
||||
* @param name Server Name
|
||||
* @param type Server Type
|
||||
* @param version Server Version
|
||||
* @param memory Server RAM Amount
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, PacketCreateServer.ServerType type, Version version, int memory, int port) {
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.memory = memory;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer will run on
|
||||
*
|
||||
* @return Potential Host
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer will use
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of Server to create
|
||||
*
|
||||
* @return Server Type
|
||||
*/
|
||||
public PacketCreateServer.ServerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Type of Server to Create
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setType(PacketCreateServer.ServerType value) {
|
||||
this.type = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Version the Server will use
|
||||
*
|
||||
* @return Server Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Version the Server will use
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setVersion(Version value) {
|
||||
this.version = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server RAM Amount (in MB)
|
||||
*
|
||||
* @return RAM Amount
|
||||
*/
|
||||
public int getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Server RAM Amount (in MB)
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setMemory(int value) {
|
||||
this.memory = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Port the Server will use
|
||||
*
|
||||
* @return Port Number
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SubDataRecieveGenericInfoEvent extends Event implements SubEvent {
|
||||
private String handle;
|
||||
private Version version;
|
||||
private JSONObject content;
|
||||
|
||||
/**
|
||||
* SubData Generic Info Event
|
||||
*
|
||||
* @param handle Content Handle
|
||||
* @param version Content Version
|
||||
* @param content Content
|
||||
*/
|
||||
public SubDataRecieveGenericInfoEvent(String handle, Version version, JSONObject content) {
|
||||
this.handle = handle;
|
||||
this.version = version;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content Handle
|
||||
*
|
||||
* @return Content Handle
|
||||
*/
|
||||
public String getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content Version
|
||||
*
|
||||
* @return Content Version
|
||||
*/
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content
|
||||
*
|
||||
* @return Content
|
||||
*/
|
||||
public JSONObject getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubRemoveServerEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private String host;
|
||||
private String server;
|
||||
|
||||
/**
|
||||
* Server Add Event
|
||||
*
|
||||
* @param player Player Adding Server
|
||||
* @param server Server Starting
|
||||
*/
|
||||
public SubRemoveServerEvent(UUID player, String host, String server) {
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server to be Added
|
||||
* @return The Server to be Added
|
||||
*/
|
||||
public String getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the Host of the Server
|
||||
*
|
||||
* @return The Host of the Server or null if isn't a SubServer
|
||||
*/
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubSendCommandEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String command;
|
||||
|
||||
/**
|
||||
* Server Command Event
|
||||
*
|
||||
* @param player Player Commanding Server
|
||||
* @param server Server being Commanded
|
||||
*/
|
||||
public SubSendCommandEvent(UUID player, String server, String command) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Effected
|
||||
* @return The Server Effected
|
||||
*/
|
||||
public String getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
/**
|
||||
* Gets the Command to Send
|
||||
*
|
||||
* @return Command to Send
|
||||
*/
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Command to be Sent
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setCommand(String value) {
|
||||
command = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubStartEvent extends Event implements SubEvent {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private String server;
|
||||
|
||||
/**
|
||||
* Server Start Event
|
||||
*
|
||||
* @param player Player Starting Server
|
||||
* @param server Server Starting
|
||||
*/
|
||||
public SubStartEvent(UUID player, String server) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Effected
|
||||
* @return The Server Effected
|
||||
*/
|
||||
public String getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubStopEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private String server;
|
||||
private boolean force;
|
||||
|
||||
/**
|
||||
* Server Stop Event
|
||||
*
|
||||
* @param player Player Stopping Server
|
||||
* @param server Server Stopping
|
||||
* @param force If it was a Forced Shutdown
|
||||
*/
|
||||
public SubStopEvent(UUID player, String server, boolean force) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Effected
|
||||
* @return The Server Effected
|
||||
*/
|
||||
public String getServer() { return server; }
|
||||
|
||||
/**
|
||||
* Gets the player that triggered the Event
|
||||
* @return The Player that triggered this Event or null if Console
|
||||
*/
|
||||
public UUID getPlayer() { return player; }
|
||||
|
||||
/**
|
||||
* Gets if it was a forced shutdown
|
||||
*
|
||||
* @return Forced Shutdown Status
|
||||
*/
|
||||
public boolean isForced() {
|
||||
return force;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class SubStoppedEvent extends Event implements SubEvent {
|
||||
private String server;
|
||||
|
||||
/**
|
||||
* Server Shell Exit Event
|
||||
*
|
||||
* @param server Server that Stopped
|
||||
*/
|
||||
public SubStoppedEvent(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Effected
|
||||
* @return The Server Effected
|
||||
*/
|
||||
public String getServer() { return server; }
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
private static HandlerList handlers = new HandlerList();
|
||||
}
|
@ -0,0 +1,365 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Graphic;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UIListener implements Listener {
|
||||
private HashMap<UUID, JSONCallback> input = new HashMap<UUID, JSONCallback>();
|
||||
private HashMap<UUID, UIRenderer> gui = new HashMap<UUID, UIRenderer>();
|
||||
private SubPlugin plugin;
|
||||
|
||||
public UIListener(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the current UIRenderer for the player
|
||||
*
|
||||
* @param player Player
|
||||
* @return UIRenderer
|
||||
*/
|
||||
public UIRenderer getRenderer(Player player) {
|
||||
if (!gui.keySet().contains(player.getUniqueId())) gui.put(player.getUniqueId(), new UIRenderer(plugin, player.getUniqueId()));
|
||||
return gui.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void click(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (!event.isCancelled() && gui.keySet().contains(player.getUniqueId())) {
|
||||
UIRenderer gui = this.gui.get(player.getUniqueId());
|
||||
if (gui.open && event.getClickedInventory() != null && event.getClickedInventory().getTitle() != null) {
|
||||
if (event.getClickedInventory().getTitle().equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&'))) { // Host Menu
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
|
||||
String item = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
|
||||
if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostMenu(gui.lastPage - 1);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostMenu(gui.lastPage + 1);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.SubServer-Menu", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverMenu(1, null);
|
||||
} else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.No-Hosts", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostAdmin(ChatColor.stripColor(item));
|
||||
}
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').split("\\$str\\$")[0]) && // Host Creator
|
||||
(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').split("\\$str\\$").length == 1 ||
|
||||
event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Title", '&').split("\\$str\\$")[1]))) {
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
|
||||
String item = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Undo", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.lastUsedOptions.undo();
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&'))) {
|
||||
if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + gui.lastVistedObject.toLowerCase())) {
|
||||
player.closeInventory();
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
plugin.subdata.sendPacket(new PacketCreateServer(player.getUniqueId(), (UIRenderer.CreatorOptions) gui.lastUsedOptions, UUID.randomUUID().toString(), json -> {
|
||||
gui.back();
|
||||
}));
|
||||
} else {
|
||||
gui.back();
|
||||
}
|
||||
} else if (ChatColor.stripColor(item).equals(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name", '&')))) {
|
||||
player.closeInventory();
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name.Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name.Message", '&'));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
if (m.getString("message").contains(" ")) {
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name.Invalid-Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name.Invalid", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20);
|
||||
} else {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, UUID.randomUUID().toString(), json -> {
|
||||
boolean match = false;
|
||||
for (String tmphost : json.getJSONObject("hosts").keySet()) {
|
||||
for (String tmpsubserver : json.getJSONObject("hosts").getJSONObject(tmphost).getJSONObject("servers").keySet()) {
|
||||
if (tmpsubserver.equalsIgnoreCase(m.getString("message"))) match = true;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
gui.setDownloading(null);
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name.Exists-Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Name.Exists", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20);
|
||||
} else {
|
||||
((UIRenderer.CreatorOptions) gui.lastUsedOptions).setName(m.getString("message"));
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions);
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
} else if (ChatColor.stripColor(item).equals(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type", '&')))) {
|
||||
player.closeInventory();
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type.Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type.Message", '&'));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
if (Util.isException(() -> PacketCreateServer.ServerType.valueOf(m.getString("message").toUpperCase()))) {
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type.Invalid-Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Type.Invalid", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20);
|
||||
} else {
|
||||
((UIRenderer.CreatorOptions) gui.lastUsedOptions).setType(PacketCreateServer.ServerType.valueOf(m.getString("message").toUpperCase()));
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions);
|
||||
}
|
||||
});
|
||||
} else if (ChatColor.stripColor(item).equals(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version", '&')))) {
|
||||
player.closeInventory();
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version.Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version.Message", '&'));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
if (new Version("1.8").compareTo(new Version(m.getString("message"))) > 0) {
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version.Unavailable-Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Version.Unavailable", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20);
|
||||
} else {
|
||||
((UIRenderer.CreatorOptions) gui.lastUsedOptions).setVersion(new Version(m.getString("message")));
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions);
|
||||
}
|
||||
});
|
||||
} else if (ChatColor.stripColor(item).equals(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port", '&')))) {
|
||||
player.closeInventory();
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port.Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port.Message", '&'));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
if (Util.isException(() -> Integer.parseInt(m.getString("message"))) || Integer.parseInt(m.getString("message")) <= 0 || Integer.parseInt(m.getString("message")) > 65535) {
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port.Invalid-Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Port.Invalid", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20);
|
||||
} else {
|
||||
((UIRenderer.CreatorOptions) gui.lastUsedOptions).setPort(Integer.valueOf(m.getString("message")));
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions);
|
||||
}
|
||||
});
|
||||
} else if (ChatColor.stripColor(item).equals(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM", '&')))) {
|
||||
player.closeInventory();
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM.Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM.Message", '&'));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
if (Util.isException(() -> Integer.parseInt(m.getString("message"))) || Integer.parseInt(m.getString("message")) < 256) {
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM.Invalid-Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-RAM.Invalid", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20);
|
||||
} else {
|
||||
((UIRenderer.CreatorOptions) gui.lastUsedOptions).setMemory(Integer.valueOf(m.getString("message")));
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&')) || // SubServer Menu
|
||||
event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$")[0]) &&
|
||||
(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$").length == 1 ||
|
||||
event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$")[1]))) {
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
|
||||
String item = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
|
||||
if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverMenu(gui.lastPage - 1, null);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverMenu(gui.lastPage + 1, null);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Host-Menu", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostMenu(1);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.No-SubServers", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverAdmin(ChatColor.stripColor(item));
|
||||
}
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').split("\\$str\\$")[0]) && // Host Admin
|
||||
(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').split("\\$str\\$").length == 1 ||
|
||||
event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Title", '&').split("\\$str\\$")[1]))) {
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
|
||||
String item = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
|
||||
if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.hostCreator(new UIRenderer.CreatorOptions(gui.lastVistedObject));
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Editor", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.host.edit.*") || player.hasPermission("subservers.host.edit." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.hostEditor(new UIRenderer.HostEditorOptions(gui.lastVistedObject));
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.SubServers", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverMenu(1, gui.lastVistedObject);
|
||||
}
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').split("\\$str\\$")[0]) && // SubServer Admin
|
||||
(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').split("\\$str\\$").length == 1 ||
|
||||
event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').split("\\$str\\$")[1]))) {
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
|
||||
String item = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
|
||||
if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Editor", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.edit.*") || player.hasPermission("subservers.subserver.edit." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.subserverEditor(new UIRenderer.SubServerEditorOptions(gui.lastVistedObject));
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.start.*") || player.hasPermission("subservers.subserver.start." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
plugin.subdata.sendPacket(new PacketStartServer(player.getUniqueId(), gui.lastVistedObject, UUID.randomUUID().toString(), json -> {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start.Title", '&'));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 30);
|
||||
}));
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.stop.*") || player.hasPermission("subservers.subserver.stop." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
final Container<Boolean> listening = new Container<Boolean>(true);
|
||||
((PacketInRunEvent) SubDataClient.getPacket("SubRunEvent")).callback("SubStoppedEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
try {
|
||||
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(gui.lastVistedObject)) {
|
||||
((PacketInRunEvent) SubDataClient.getPacket("RunEvent")).callback("SubStoppedEvent", this);
|
||||
} else {
|
||||
gui.reopen();
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), gui.lastVistedObject, false, UUID.randomUUID().toString(), json -> {
|
||||
if (json.getInt("r") != 0) {
|
||||
gui.reopen();
|
||||
listening.set(false);
|
||||
} else gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop.Title", '&').replace("$str$", gui.lastVistedObject));
|
||||
}));
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.terminate.*") || player.hasPermission("subservers.subserver.terminate." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
final Container<Boolean> listening = new Container<Boolean>(true);
|
||||
((PacketInRunEvent) SubDataClient.getPacket("SubRunEvent")).callback("SubStoppedEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
try {
|
||||
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(gui.lastVistedObject)) {
|
||||
((PacketInRunEvent) SubDataClient.getPacket("RunEvent")).callback("SubStoppedEvent", this);
|
||||
} else {
|
||||
gui.reopen();
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), gui.lastVistedObject, false, UUID.randomUUID().toString(), json -> {
|
||||
if (json.getInt("r") != 0) {
|
||||
gui.reopen();
|
||||
listening.set(false);
|
||||
} else gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate.Title", '&').replace("$str$", gui.lastVistedObject));
|
||||
}));
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.command.*") || player.hasPermission("subservers.subserver.command." + gui.lastVistedObject.toLowerCase())) {
|
||||
if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command.Title", '&'), 4 * 20))
|
||||
player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command.Message", '&'));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
plugin.subdata.sendPacket(new PacketCommandServer(player.getUniqueId(), gui.lastVistedObject, m.getString("message"), UUID.randomUUID().toString(), json -> {
|
||||
gui.reopen();
|
||||
}));
|
||||
});
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Teleport", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.teleport.*") || player.hasPermission("subservers.subserver.teleport." + gui.lastVistedObject.toLowerCase())) {
|
||||
gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&'));
|
||||
plugin.subdata.sendPacket(new PacketTeleportPlayer(player.getUniqueId(), gui.lastVistedObject, UUID.randomUUID().toString(), json -> {
|
||||
if (json.getInt("r") != 0) gui.reopen();
|
||||
}));
|
||||
} else gui.reopen();
|
||||
}
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void input(org.bukkit.event.player.PlayerChatEvent event) {
|
||||
if (!event.isCancelled() && input.keySet().contains(event.getPlayer().getUniqueId())) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("message", event.getMessage());
|
||||
input.get(event.getPlayer().getUniqueId()).run(json);
|
||||
input.remove(event.getPlayer().getUniqueId());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void input(PlayerCommandPreprocessEvent event) {
|
||||
if (!event.isCancelled() && input.keySet().contains(event.getPlayer().getUniqueId())) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("message", event.getMessage());
|
||||
input.get(event.getPlayer().getUniqueId()).run(json);
|
||||
input.remove(event.getPlayer().getUniqueId());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void close(InventoryCloseEvent event) {
|
||||
if (gui.keySet().contains(event.getPlayer().getUniqueId())) gui.get(event.getPlayer().getUniqueId()).open = false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void clean(PlayerQuitEvent event) {
|
||||
if (gui.keySet().contains(event.getPlayer().getUniqueId())) {
|
||||
gui.get(event.getPlayer().getUniqueId()).setDownloading(null);
|
||||
gui.remove(event.getPlayer().getUniqueId());
|
||||
input.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,65 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Config;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class YAMLConfig {
|
||||
private File file;
|
||||
private Yaml yaml;
|
||||
private YAMLSection config;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLConfig(File file) throws IOException, YAMLException {
|
||||
if (file.exists()) {
|
||||
this.config = new YAMLSection((Map<String, ?>) (this.yaml = new Yaml(getDumperOptions())).load(new FileInputStream(this.file = file)), null, null, yaml);
|
||||
} else {
|
||||
this.config = new YAMLSection(null, null, null, yaml);
|
||||
}
|
||||
}
|
||||
|
||||
public YAMLSection get() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void set(YAMLSection yaml) {
|
||||
config = yaml;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void reload() throws IOException {
|
||||
config = new YAMLSection((Map<String, Object>) yaml.load(new FileInputStream(file)), null, null, yaml);
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
FileWriter writer = new FileWriter(file);
|
||||
yaml.dump(config.map, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return yaml.dump(config.map);
|
||||
}
|
||||
|
||||
public JSONObject toJSON() {
|
||||
return new JSONObject(config.map);
|
||||
}
|
||||
|
||||
protected static DumperOptions getDumperOptions() {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setAllowUnicode(true);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
options.setIndent(4);
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
@ -0,0 +1,513 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Config;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.json.JSONObject;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public class YAMLSection {
|
||||
protected Map<String, Object> map;
|
||||
protected String label = null;
|
||||
protected YAMLSection up = null;
|
||||
private Yaml yaml;
|
||||
|
||||
public YAMLSection() {
|
||||
this.map = new HashMap<>();
|
||||
this.yaml = new Yaml(YAMLConfig.getDumperOptions());
|
||||
}
|
||||
|
||||
public YAMLSection(InputStream io) throws YAMLException {
|
||||
this.map = (Map<String, Object>) (this.yaml = new Yaml(YAMLConfig.getDumperOptions())).load(io);
|
||||
}
|
||||
|
||||
public YAMLSection(Reader reader) throws YAMLException {
|
||||
this.map = (Map<String, Object>) (this.yaml = new Yaml(YAMLConfig.getDumperOptions())).load(reader);
|
||||
}
|
||||
|
||||
public YAMLSection(JSONObject json) {
|
||||
this.map = (Map<String, Object>) (this.yaml = new Yaml(YAMLConfig.getDumperOptions())).load(json.toString(4));
|
||||
}
|
||||
|
||||
public YAMLSection(String yaml) throws YAMLException {
|
||||
this.map = (Map<String, Object>) (this.yaml = new Yaml(YAMLConfig.getDumperOptions())).load(yaml);
|
||||
}
|
||||
|
||||
protected YAMLSection(Map<String, ?> map, YAMLSection up, String label, Yaml yaml) {
|
||||
this.map = new HashMap<String, Object>();
|
||||
this.yaml = yaml;
|
||||
this.label = label;
|
||||
this.up = up;
|
||||
|
||||
if (map != null) {
|
||||
for (String key : map.keySet()) {
|
||||
this.map.put(key, map.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getKeys() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
|
||||
public Collection<YAMLValue> getValues() {
|
||||
List<YAMLValue> values = new ArrayList<YAMLValue>();
|
||||
for (String value : map.keySet()) {
|
||||
values.add(new YAMLValue(map.get(value), this, value, yaml));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public boolean contains(String label) {
|
||||
return map.keySet().contains(label);
|
||||
}
|
||||
|
||||
public void remove(String label) {
|
||||
map.remove(label);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
public void set(String label, Object value) {
|
||||
if (value instanceof YAMLConfig) { // YAML Handler Values
|
||||
((YAMLConfig) value).get().up = this;
|
||||
((YAMLConfig) value).get().label = label;
|
||||
map.put(label, ((YAMLConfig) value).get().map);
|
||||
} else if (value instanceof YAMLSection) {
|
||||
((YAMLSection) value).up = this;
|
||||
((YAMLSection) value).label = label;
|
||||
map.put(label, ((YAMLSection) value).map);
|
||||
} else if (value instanceof YAMLValue) {
|
||||
map.put(label, ((YAMLValue) value).asObject());
|
||||
} else {
|
||||
map.put(label, value);
|
||||
}
|
||||
|
||||
if (this.label != null && this.up != null) {
|
||||
this.up.set(this.label, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAll(Map<String, ?> values) {
|
||||
for (String value : values.keySet()) {
|
||||
set(value, values.get(value));
|
||||
}
|
||||
}
|
||||
|
||||
public void setAll(YAMLSection values) {
|
||||
for (String value : values.map.keySet()) {
|
||||
set(value, values.map.get(value));
|
||||
}
|
||||
}
|
||||
|
||||
public YAMLSection superSection() {
|
||||
return up;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return yaml.dump(map);
|
||||
}
|
||||
|
||||
public JSONObject toJSON() {
|
||||
return new JSONObject(map);
|
||||
}
|
||||
|
||||
public YAMLValue get(String label) {
|
||||
return (map.get(label) != null)?(new YAMLValue(map.get(label), this, label, yaml)):null;
|
||||
}
|
||||
|
||||
public YAMLValue get(String label, Object def) {
|
||||
return new YAMLValue((map.get(label) != null)?map.get(label):def, this, label, yaml);
|
||||
}
|
||||
|
||||
public YAMLValue get(String label, YAMLValue def) {
|
||||
return (map.get(label) != null) ? (new YAMLValue(map.get(label), this, label, yaml)) : def;
|
||||
}
|
||||
|
||||
public List<YAMLValue> getList(String label) {
|
||||
if (map.get(label) != null) {
|
||||
List<YAMLValue> values = new ArrayList<YAMLValue>();
|
||||
for (Object value : (List<?>) map.get(label)) {
|
||||
values.add(new YAMLValue(value, null, null, yaml));
|
||||
}
|
||||
return values;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<YAMLValue> getList(String label, Collection<?> def) {
|
||||
if (map.get(label) != null) {
|
||||
return getList(label);
|
||||
} else {
|
||||
List<YAMLValue> values = new ArrayList<YAMLValue>();
|
||||
for (Object value : def) {
|
||||
values.add(new YAMLValue(value, null, null, yaml));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public List<YAMLValue> getList(String label, List<? extends YAMLValue> def) {
|
||||
if (map.get(label) != null) {
|
||||
return getList(label);
|
||||
} else {
|
||||
List<YAMLValue> values = new ArrayList<YAMLValue>();
|
||||
for (YAMLValue value : def) {
|
||||
values.add(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getObject(String label) {
|
||||
return map.get(label);
|
||||
}
|
||||
|
||||
public Object getObject(String label, Object def) {
|
||||
return (map.get(label) != null)?map.get(label):def;
|
||||
}
|
||||
|
||||
public List<?> getObjectList(String label) {
|
||||
return (List<?>) map.get(label);
|
||||
}
|
||||
|
||||
public List<?> getObjectList(String label, List<?> def) {
|
||||
return (List<?>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String label) {
|
||||
return (boolean) map.get(label);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String label, boolean def) {
|
||||
return (boolean) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<Boolean> getBooleanList(String label) {
|
||||
return (List<Boolean>) map.get(label);
|
||||
}
|
||||
|
||||
public List<Boolean> getBooleanList(String label, List<Boolean> def) {
|
||||
return (List<Boolean>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public YAMLSection getSection(String label) {
|
||||
return (map.get(label) != null)?(new YAMLSection((Map<String, Object>) map.get(label), this, label, yaml)):null;
|
||||
}
|
||||
|
||||
public YAMLSection getSection(String label, Map<String, ?> def) {
|
||||
return new YAMLSection((Map<String, Object>) ((map.get(label) != null)?map.get(label):def), this, label, yaml);
|
||||
}
|
||||
|
||||
public YAMLSection getSection(String label, YAMLSection def) {
|
||||
return (map.get(label) != null)?(new YAMLSection((Map<String, Object>) map.get(label), this, label, yaml)):def;
|
||||
}
|
||||
|
||||
public List<YAMLSection> getSectionList(String label) {
|
||||
if (map.get(label) != null) {
|
||||
List<YAMLSection> values = new ArrayList<YAMLSection>();
|
||||
for (Map<String, ?> value : (List<? extends Map<String, ?>>) map.get(label)) {
|
||||
values.add(new YAMLSection(value, null, null, yaml));
|
||||
}
|
||||
return values;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<YAMLSection> getSectionList(String label, Collection<? extends Map<String, ?>> def) {
|
||||
if (map.get(label) != null) {
|
||||
return getSectionList(label);
|
||||
} else {
|
||||
List<YAMLSection> values = new ArrayList<YAMLSection>();
|
||||
for (Map<String, ?> value : def) {
|
||||
values.add(new YAMLSection(value, null, null, yaml));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public List<YAMLSection> getSectionList(String label, List<? extends YAMLSection> def) {
|
||||
if (map.get(label) != null) {
|
||||
return getSectionList(label);
|
||||
} else {
|
||||
List<YAMLSection> values = new ArrayList<YAMLSection>();
|
||||
for (YAMLSection value : def) {
|
||||
values.add(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public double getDouble(String label) {
|
||||
return (double) map.get(label);
|
||||
}
|
||||
|
||||
public double getDouble(String label, double def) {
|
||||
return (double) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<Double> getDoubleList(String label) {
|
||||
return (List<Double>) map.get(label);
|
||||
}
|
||||
|
||||
public List<Double> getDoubleList(String label, List<Double> def) {
|
||||
return (List<Double>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public float getFloat(String label) {
|
||||
return (float) map.get(label);
|
||||
}
|
||||
|
||||
public float getFloat(String label, float def) {
|
||||
return (float) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<Float> getFloatList(String label) {
|
||||
return (List<Float>) map.get(label);
|
||||
}
|
||||
|
||||
public List<Float> getFloatList(String label, float def) {
|
||||
return (List<Float>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public int getInt(String label) {
|
||||
return (int) map.get(label);
|
||||
}
|
||||
|
||||
public int getInt(String label, int def) {
|
||||
return (int) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<Integer> getIntList(String label) {
|
||||
return (List<Integer>) map.get(label);
|
||||
}
|
||||
|
||||
public List<Integer> getIntList(String label, List<Integer> def) {
|
||||
return (List<Integer>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public long getLong(String label) {
|
||||
return (long) map.get(label);
|
||||
}
|
||||
|
||||
public long getLong(String label, long def) {
|
||||
return (long) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<Long> getLongList(String label) {
|
||||
return (List<Long>) map.get(label);
|
||||
}
|
||||
|
||||
public List<Long> getLongList(String label, List<Long> def) {
|
||||
return (List<Long>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public short getShort(String label) {
|
||||
return (short) map.get(label);
|
||||
}
|
||||
|
||||
public short getShort(String label, short def) {
|
||||
return (short) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<Short> getShortList(String label) {
|
||||
return (List<Short>) map.get(label);
|
||||
}
|
||||
|
||||
public List<Short> getShortList(String label, List<Short> def) {
|
||||
return (List<Short>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public String getRawString(String label) {
|
||||
return (String) map.get(label);
|
||||
}
|
||||
|
||||
public String getRawString(String label, String def) {
|
||||
return (String) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public List<String> getRawStringList(String label) {
|
||||
return (List<String>) map.get(label);
|
||||
}
|
||||
|
||||
public List<String> getRawStringList(String label, List<String> def) {
|
||||
return (List<String>) ((map.get(label) != null)?map.get(label):def);
|
||||
}
|
||||
|
||||
public String getString(String label) {
|
||||
return (map.get(label) != null)?unescapeJavaString((String) map.get(label)):null;
|
||||
}
|
||||
|
||||
public String getString(String label, String def) {
|
||||
return unescapeJavaString((String) ((map.get(label) != null) ? map.get(label) : def));
|
||||
}
|
||||
|
||||
public List<String> getStringList(String label) {
|
||||
if (map.get(label) != null) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : (List<String>) map.get(label)) {
|
||||
values.add(unescapeJavaString(value));
|
||||
}
|
||||
return values;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getStringList(String label, List<String> def) {
|
||||
if (map.get(label) != null) {
|
||||
return getStringList(label);
|
||||
} else {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : def) {
|
||||
values.add(unescapeJavaString(value));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public String getColoredString(String label, char color) {
|
||||
return (map.get(label) != null)? ChatColor.translateAlternateColorCodes(color, unescapeJavaString((String) map.get(label))):null;
|
||||
}
|
||||
|
||||
public String getColoredString(String label, String def, char color) {
|
||||
return ChatColor.translateAlternateColorCodes(color, unescapeJavaString((String) ((map.get(label) != null) ? map.get(label) : def)));
|
||||
}
|
||||
|
||||
public List<String> getColoredStringList(String label, char color) {
|
||||
if (map.get(label) != null) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : (List<String>) map.get(label)) {
|
||||
values.add(ChatColor.translateAlternateColorCodes(color, unescapeJavaString(value)));
|
||||
}
|
||||
return values;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getColoredStringList(String label, List<String> def, char color) {
|
||||
if (map.get(label) != null) {
|
||||
return getColoredStringList(label, color);
|
||||
} else {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : def) {
|
||||
values.add(ChatColor.translateAlternateColorCodes(color, unescapeJavaString(value)));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBoolean(String label) {
|
||||
return (map.get(label) instanceof Boolean);
|
||||
}
|
||||
|
||||
public boolean isSection(String label) {
|
||||
return (map.get(label) instanceof Map);
|
||||
}
|
||||
|
||||
public boolean isDouble(String label) {
|
||||
return (map.get(label) instanceof Double);
|
||||
}
|
||||
|
||||
public boolean isFloat(String label) {
|
||||
return (map.get(label) instanceof Float);
|
||||
}
|
||||
|
||||
public boolean isInt(String label) {
|
||||
return (map.get(label) instanceof Integer);
|
||||
}
|
||||
|
||||
public boolean isList(String label) {
|
||||
return (map.get(label) instanceof List);
|
||||
}
|
||||
|
||||
public boolean isLong(String label) {
|
||||
return (map.get(label) instanceof Long);
|
||||
}
|
||||
|
||||
public boolean isString(String label) {
|
||||
return (map.get(label) instanceof String);
|
||||
}
|
||||
|
||||
static String unescapeJavaString(String str) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch == '\\') {
|
||||
char nextChar = (i == str.length() - 1) ? '\\' : str
|
||||
.charAt(i + 1);
|
||||
// Octal escape?
|
||||
if (nextChar >= '0' && nextChar <= '7') {
|
||||
String code = "" + nextChar;
|
||||
i++;
|
||||
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
|
||||
&& str.charAt(i + 1) <= '7') {
|
||||
code += str.charAt(i + 1);
|
||||
i++;
|
||||
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
|
||||
&& str.charAt(i + 1) <= '7') {
|
||||
code += str.charAt(i + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sb.append((char) Integer.parseInt(code, 8));
|
||||
continue;
|
||||
}
|
||||
switch (nextChar) {
|
||||
case '\\':
|
||||
ch = '\\';
|
||||
break;
|
||||
case 'b':
|
||||
ch = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
ch = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
case '\"':
|
||||
ch = '\"';
|
||||
break;
|
||||
case '\'':
|
||||
ch = '\'';
|
||||
break;
|
||||
// Hex Unicode: u????
|
||||
case 'u':
|
||||
if (i >= str.length() - 5) {
|
||||
ch = 'u';
|
||||
break;
|
||||
}
|
||||
int code = Integer.parseInt(
|
||||
"" + str.charAt(i + 2) + str.charAt(i + 3)
|
||||
+ str.charAt(i + 4) + str.charAt(i + 5), 16);
|
||||
sb.append(Character.toChars(code));
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sb.append(ch);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Config;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public class YAMLValue {
|
||||
protected Object obj;
|
||||
protected String label;
|
||||
protected YAMLSection up;
|
||||
private Yaml yaml;
|
||||
|
||||
public YAMLValue(Object obj, YAMLSection up, String label, Yaml yaml) {
|
||||
this.obj = obj;
|
||||
this.label = label;
|
||||
this.yaml = yaml;
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
public YAMLSection getDefiningSection() {
|
||||
return up;
|
||||
}
|
||||
|
||||
public Object asObject() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public List<?> asObjectList() {
|
||||
return (List<?>) obj;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
return (boolean) obj;
|
||||
}
|
||||
|
||||
public List<Boolean> asBooleanList() {
|
||||
return (List<Boolean>) obj;
|
||||
}
|
||||
|
||||
public YAMLSection asSection() {
|
||||
return new YAMLSection((Map<String, ?>) obj, up, label, yaml);
|
||||
}
|
||||
|
||||
public List<YAMLSection> asSectionList() {
|
||||
List<YAMLSection> values = new ArrayList<YAMLSection>();
|
||||
for (Map<String, ?> value : (List<? extends Map<String, ?>>) obj) {
|
||||
values.add(new YAMLSection(value, null, null, yaml));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public double asDouble() {
|
||||
return (double) obj;
|
||||
}
|
||||
|
||||
public List<Double> asDoubleList() {
|
||||
return (List<Double>) obj;
|
||||
}
|
||||
|
||||
public float asFloat() {
|
||||
return (float) obj;
|
||||
}
|
||||
|
||||
public List<Float> asFloatList() {
|
||||
return (List<Float>) obj;
|
||||
}
|
||||
|
||||
public int asInt() {
|
||||
return (int) obj;
|
||||
}
|
||||
|
||||
public List<Integer> asIntList() {
|
||||
return (List<Integer>) obj;
|
||||
}
|
||||
|
||||
public long asLong() {
|
||||
return (long) obj;
|
||||
}
|
||||
|
||||
public List<Long> asLongList() {
|
||||
return (List<Long>) obj;
|
||||
}
|
||||
|
||||
public String asRawString() {
|
||||
return (String) obj;
|
||||
}
|
||||
|
||||
public List<String> asRawStringList() {
|
||||
return (List<String>) obj;
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
return YAMLSection.unescapeJavaString((String) obj);
|
||||
}
|
||||
|
||||
public List<String> asStringList() {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : (List<String>) obj) {
|
||||
values.add(YAMLSection.unescapeJavaString(value));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public String asColoredString(char color) {
|
||||
return ChatColor.translateAlternateColorCodes(color, YAMLSection.unescapeJavaString((String) obj));
|
||||
}
|
||||
|
||||
public List<String> asColoredStringList(char color) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : (List<String>) obj) {
|
||||
values.add(ChatColor.translateAlternateColorCodes(color, YAMLSection.unescapeJavaString(value)));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public boolean isBoolean() {
|
||||
return (obj instanceof Boolean);
|
||||
}
|
||||
|
||||
public boolean isSection() {
|
||||
return (obj instanceof Map);
|
||||
}
|
||||
|
||||
public boolean isDouble() {
|
||||
return (obj instanceof Double);
|
||||
}
|
||||
|
||||
public boolean isFloat(String path) {
|
||||
return (obj instanceof Float);
|
||||
}
|
||||
|
||||
public boolean isInt() {
|
||||
return (obj instanceof Integer);
|
||||
}
|
||||
|
||||
public boolean isList() {
|
||||
return (obj instanceof List);
|
||||
}
|
||||
|
||||
public boolean isLong() {
|
||||
return (obj instanceof Long);
|
||||
}
|
||||
|
||||
public boolean isString() {
|
||||
return (obj instanceof String);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library;
|
||||
|
||||
/**
|
||||
* Container Class
|
||||
*
|
||||
* @author ME1312
|
||||
*/
|
||||
public class Container<V> {
|
||||
private V obj;
|
||||
|
||||
/**
|
||||
* Creates a Container
|
||||
*
|
||||
* @param item Object to Store
|
||||
*/
|
||||
public Container(V item) {
|
||||
obj = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Object
|
||||
*
|
||||
* @return The Object
|
||||
*/
|
||||
public V get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the Object
|
||||
*
|
||||
* @param value Object to Store
|
||||
*/
|
||||
public void set(V value) {
|
||||
obj = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Exception;
|
||||
|
||||
public class IllegalPacketException extends IllegalStateException {
|
||||
public IllegalPacketException() {}
|
||||
public IllegalPacketException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public interface JSONCallback {
|
||||
void run(JSONObject json);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library;
|
||||
|
||||
public class NamedContainer<T, V> extends Container<V> {
|
||||
private T name;
|
||||
|
||||
/**
|
||||
* Creates a TaggedContainer
|
||||
*
|
||||
* @param name Tag to Bind
|
||||
* @param item Object to Store
|
||||
*/
|
||||
public NamedContainer(T name, V item) {
|
||||
super(item);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the Container
|
||||
*
|
||||
* @return Container name
|
||||
*/
|
||||
public T name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames the Container
|
||||
*
|
||||
* @param name New Container Name
|
||||
*/
|
||||
public void rename(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library;
|
||||
|
||||
public interface SubEvent {
|
||||
/*
|
||||
This Class is used to define a SubEvent
|
||||
*/
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Universal File Class
|
||||
*
|
||||
* @author ME1312
|
||||
*/
|
||||
public class UniversalFile extends File {
|
||||
|
||||
/**
|
||||
* Creates a File Link. Path names are separated by ':'
|
||||
*
|
||||
* @param pathname Path name
|
||||
*/
|
||||
public UniversalFile(String pathname) {
|
||||
super(pathname.replace(".:", System.getProperty("user.dir") + ":").replace(':', File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File Link. Path names are separated by the divider
|
||||
*
|
||||
* @param pathname Path name
|
||||
* @param divider Divider to use
|
||||
*/
|
||||
public UniversalFile(String pathname, char divider) {
|
||||
super(pathname.replace("." + divider, System.getProperty("user.dir") + divider).replace(divider, File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File Link.
|
||||
*
|
||||
* @see File
|
||||
* @param file File
|
||||
*/
|
||||
public UniversalFile(File file) {
|
||||
super(file.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File. Path names are separated by the ':'
|
||||
*
|
||||
* @see File
|
||||
* @param parent Parent File
|
||||
* @param child Path name
|
||||
*/
|
||||
public UniversalFile(File parent, String child) {
|
||||
super(parent, child.replace(':', File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File. Path names are separated by the divider
|
||||
*
|
||||
* @see File
|
||||
* @param parent Parent File
|
||||
* @param child Path name
|
||||
* @param divider Divider to use
|
||||
*/
|
||||
public UniversalFile(File parent, String child, char divider) {
|
||||
super(parent, child.replace(divider, File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Universal File Path (separated by ':')
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUniversalPath() {
|
||||
return getPath().replace(File.separatorChar, ':');
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public final class Util {
|
||||
public static String readAll(Reader rd) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int cp;
|
||||
while ((cp = rd.read()) != -1) {
|
||||
sb.append((char) cp);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void copyFromJar(ClassLoader loader, String resource, String destination) {
|
||||
InputStream resStreamIn = loader.getResourceAsStream(resource);
|
||||
File resDestFile = new File(destination);
|
||||
try {
|
||||
OutputStream resStreamOut = new FileOutputStream(resDestFile);
|
||||
int readBytes;
|
||||
byte[] buffer = new byte[4096];
|
||||
while ((readBytes = resStreamIn.read(buffer)) > 0) {
|
||||
resStreamOut.write(buffer, 0, readBytes);
|
||||
}
|
||||
resStreamOut.close();
|
||||
resStreamIn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isException(Runnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
return false;
|
||||
} catch (Throwable e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static String unescapeJavaString(String str) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch == '\\') {
|
||||
char nextChar = (i == str.length() - 1) ? '\\' : str
|
||||
.charAt(i + 1);
|
||||
// Octal escape?
|
||||
if (nextChar >= '0' && nextChar <= '7') {
|
||||
String code = "" + nextChar;
|
||||
i++;
|
||||
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
|
||||
&& str.charAt(i + 1) <= '7') {
|
||||
code += str.charAt(i + 1);
|
||||
i++;
|
||||
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
|
||||
&& str.charAt(i + 1) <= '7') {
|
||||
code += str.charAt(i + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sb.append((char) Integer.parseInt(code, 8));
|
||||
continue;
|
||||
}
|
||||
switch (nextChar) {
|
||||
case '\\':
|
||||
ch = '\\';
|
||||
break;
|
||||
case 'b':
|
||||
ch = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
ch = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
case '\"':
|
||||
ch = '\"';
|
||||
break;
|
||||
case '\'':
|
||||
ch = '\'';
|
||||
break;
|
||||
// Hex Unicode: u????
|
||||
case 'u':
|
||||
if (i >= str.length() - 5) {
|
||||
ch = 'u';
|
||||
break;
|
||||
}
|
||||
int code = Integer.parseInt(
|
||||
"" + str.charAt(i + 2) + str.charAt(i + 3)
|
||||
+ str.charAt(i + 4) + str.charAt(i + 5), 16);
|
||||
sb.append(Character.toChars(code));
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sb.append(ch);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Version Class
|
||||
*
|
||||
* @author ME1312
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class Version implements Serializable, Comparable<Version> {
|
||||
private String string;
|
||||
|
||||
/**
|
||||
* Creates a Version
|
||||
*
|
||||
* @param string Version String
|
||||
*/
|
||||
public Version(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Version
|
||||
*
|
||||
* @param ints Version Numbers (Will be separated with dots)
|
||||
*/
|
||||
public Version(Integer... ints) {
|
||||
String string = Integer.toString(ints[0]);
|
||||
int i = 0;
|
||||
if (ints.length != 1) {
|
||||
do {
|
||||
i++;
|
||||
string = string + "." + ints[i];
|
||||
} while ((i + 1) != ints.length);
|
||||
}
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if Versions are Equal
|
||||
*
|
||||
* @param version Version to Compare
|
||||
* @return
|
||||
*/
|
||||
public boolean equals(Version version) {
|
||||
return compareTo(version) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 1 if Greater than
|
||||
* Returns 0 if Equal
|
||||
* Returns -1 if Less than
|
||||
*//**
|
||||
*
|
||||
* Compare Versions
|
||||
*
|
||||
* @param version The version to compare to
|
||||
*/
|
||||
public int compareTo(Version version) {
|
||||
String version1 = this.string;
|
||||
String version2 = version.toString();
|
||||
|
||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
||||
|
||||
int number1 = 0, number2 = 0;
|
||||
String suffix1 = "", suffix2 = "";
|
||||
|
||||
while (tokenizer1.MoveNext()) {
|
||||
if (!tokenizer2.MoveNext()) {
|
||||
do {
|
||||
number1 = tokenizer1.getNumber();
|
||||
suffix1 = tokenizer1.getSuffix();
|
||||
if (number1 != 0 || suffix1.length() != 0) {
|
||||
// Version one is longer than number two, and non-zero
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
while (tokenizer1.MoveNext());
|
||||
|
||||
// Version one is longer than version two, but zero
|
||||
return 0;
|
||||
}
|
||||
|
||||
number1 = tokenizer1.getNumber();
|
||||
suffix1 = tokenizer1.getSuffix();
|
||||
number2 = tokenizer2.getNumber();
|
||||
suffix2 = tokenizer2.getSuffix();
|
||||
|
||||
if (number1 < number2) {
|
||||
// Number one is less than number two
|
||||
return -1;
|
||||
}
|
||||
if (number1 > number2) {
|
||||
// Number one is greater than number two
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean empty1 = suffix1.length() == 0;
|
||||
boolean empty2 = suffix2.length() == 0;
|
||||
|
||||
if (empty1 && empty2) continue; // No suffixes
|
||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
||||
|
||||
// Lexical comparison of suffixes
|
||||
int result = suffix1.compareTo(suffix2);
|
||||
if (result != 0) return result;
|
||||
|
||||
}
|
||||
if (tokenizer2.MoveNext()) {
|
||||
do {
|
||||
number2 = tokenizer2.getNumber();
|
||||
suffix2 = tokenizer2.getSuffix();
|
||||
if (number2 != 0 || suffix2.length() != 0) {
|
||||
// Version one is longer than version two, and non-zero
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (tokenizer2.MoveNext());
|
||||
|
||||
// Version two is longer than version one, but zero
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if Versions are Equal
|
||||
*
|
||||
* @param ver1 Version to Compare
|
||||
* @param ver2 Version to Compare
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEqual(Version ver1, Version ver2) {
|
||||
return compare(ver1, ver2) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 1 if Greater than
|
||||
* Returns 0 if Equal
|
||||
* Returns -1 if Less than
|
||||
*//**
|
||||
* Compare Versions
|
||||
*
|
||||
* @param ver1 Version to Compare
|
||||
* @param ver2 Version to Compare
|
||||
*/
|
||||
public static int compare(Version ver1, Version ver2) {
|
||||
String version1 = ver1.toString();
|
||||
String version2 = ver2.toString();
|
||||
|
||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
||||
|
||||
int number1 = 0, number2 = 0;
|
||||
String suffix1 = "", suffix2 = "";
|
||||
|
||||
while (tokenizer1.MoveNext()) {
|
||||
if (!tokenizer2.MoveNext()) {
|
||||
do {
|
||||
number1 = tokenizer1.getNumber();
|
||||
suffix1 = tokenizer1.getSuffix();
|
||||
if (number1 != 0 || suffix1.length() != 0) {
|
||||
// Version one is longer than number two, and non-zero
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
while (tokenizer1.MoveNext());
|
||||
|
||||
// Version one is longer than version two, but zero
|
||||
return 0;
|
||||
}
|
||||
|
||||
number1 = tokenizer1.getNumber();
|
||||
suffix1 = tokenizer1.getSuffix();
|
||||
number2 = tokenizer2.getNumber();
|
||||
suffix2 = tokenizer2.getSuffix();
|
||||
|
||||
if (number1 < number2) {
|
||||
// Number one is less than number two
|
||||
return -1;
|
||||
}
|
||||
if (number1 > number2) {
|
||||
// Number one is greater than number two
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean empty1 = suffix1.length() == 0;
|
||||
boolean empty2 = suffix2.length() == 0;
|
||||
|
||||
if (empty1 && empty2) continue; // No suffixes
|
||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
||||
|
||||
// Lexical comparison of suffixes
|
||||
int result = suffix1.compareTo(suffix2);
|
||||
if (result != 0) return result;
|
||||
|
||||
}
|
||||
if (tokenizer2.MoveNext()) {
|
||||
do {
|
||||
number2 = tokenizer2.getNumber();
|
||||
suffix2 = tokenizer2.getSuffix();
|
||||
if (number2 != 0 || suffix2.length() != 0) {
|
||||
// Version one is longer than version two, and non-zero
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (tokenizer2.MoveNext());
|
||||
|
||||
// Version two is longer than version one, but zero
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Version;
|
||||
|
||||
public final class VersionTokenizer {
|
||||
private final String _versionString;
|
||||
private final int _length;
|
||||
|
||||
private int _position;
|
||||
private int _number;
|
||||
private String _suffix;
|
||||
private boolean _hasValue;
|
||||
|
||||
protected int getNumber() {
|
||||
return _number;
|
||||
}
|
||||
|
||||
protected String getSuffix() {
|
||||
return _suffix;
|
||||
}
|
||||
|
||||
protected boolean hasValue() {
|
||||
return _hasValue;
|
||||
}
|
||||
|
||||
protected VersionTokenizer(String versionString) {
|
||||
if (versionString == null)
|
||||
throw new IllegalArgumentException("versionString is null");
|
||||
|
||||
_versionString = versionString;
|
||||
_length = versionString.length();
|
||||
}
|
||||
|
||||
protected boolean MoveNext() {
|
||||
_number = 0;
|
||||
_suffix = "";
|
||||
_hasValue = false;
|
||||
|
||||
// No more characters
|
||||
if (_position >= _length)
|
||||
return false;
|
||||
|
||||
_hasValue = true;
|
||||
|
||||
while (_position < _length) {
|
||||
char c = _versionString.charAt(_position);
|
||||
if (c < '0' || c > '9') break;
|
||||
_number = _number * 10 + (c - '0');
|
||||
_position++;
|
||||
}
|
||||
|
||||
int suffixStart = _position;
|
||||
|
||||
while (_position < _length) {
|
||||
char c = _versionString.charAt(_position);
|
||||
if (c == '.') break;
|
||||
_position++;
|
||||
}
|
||||
|
||||
_suffix = _versionString.substring(suffixStart, _position);
|
||||
|
||||
if (_position < _length) _position++;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
public PacketAuthorization(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("password", plugin.pluginconf.get().getSection("Settings").getSection("SubData").getString("Password"));
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
plugin.subdata.sendPacket(new PacketLinkServer(plugin));
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang());
|
||||
} else {
|
||||
Bukkit.getLogger().info("SubServers > Could not authorize SubData connection: " + data.getString("m"));
|
||||
plugin.subdata.destroy(false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String command;
|
||||
private String id;
|
||||
|
||||
public PacketCommandServer() {}
|
||||
public PacketCommandServer(String server, String command, String id, JSONCallback callback) {
|
||||
this.player = null;
|
||||
this.server = server;
|
||||
this.command = command;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
public PacketCommandServer(UUID player, String server, String command, String id, JSONCallback callback) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.command = command;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
if (player != null) json.put("player", player.toString());
|
||||
json.put("server", server);
|
||||
json.put("command", command);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
public enum ServerType {
|
||||
SPIGOT,
|
||||
VANILLA,
|
||||
SPONGE,;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().substring(0, 1).toUpperCase()+super.toString().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
private UUID player;
|
||||
private String name;
|
||||
private String host;
|
||||
private ServerType type;
|
||||
private Version version;
|
||||
private int port;
|
||||
private int ram;
|
||||
private String id;
|
||||
|
||||
public PacketCreateServer() {}
|
||||
public PacketCreateServer(String name, String host, ServerType type, Version version, int port, int memory, String id, JSONCallback callback) {
|
||||
this.player = null;
|
||||
this.name = name;
|
||||
this.host = host;
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.ram = memory;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
public PacketCreateServer(UUID player, String name, String host, ServerType type, Version version, int port, int memory, String id, JSONCallback callback) {
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.host = host;
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.ram = memory;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
public PacketCreateServer(UIRenderer.CreatorOptions options, String id, JSONCallback callback) {
|
||||
this.player = null;
|
||||
this.name = options.getName();
|
||||
this.host = options.getHost();
|
||||
this.type = options.getType();
|
||||
this.version = options.getVersion();
|
||||
this.port = options.getPort();
|
||||
this.ram = options.getMemory();
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
|
||||
}
|
||||
public PacketCreateServer(UUID player, UIRenderer.CreatorOptions options, String id, JSONCallback callback) {
|
||||
this.player = player;
|
||||
this.name = options.getName();
|
||||
this.host = options.getHost();
|
||||
this.type = options.getType();
|
||||
this.version = options.getVersion();
|
||||
this.port = options.getPort();
|
||||
this.ram = options.getMemory();
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
if (player != null) json.put("player", player.toString());
|
||||
JSONObject creator = new JSONObject();
|
||||
creator.put("name", name);
|
||||
creator.put("host", host);
|
||||
creator.put("type", type.toString());
|
||||
creator.put("version", version.toString());
|
||||
creator.put("port", port);
|
||||
creator.put("ram", ram);
|
||||
json.put("creator", creator);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private String host;
|
||||
private String id;
|
||||
|
||||
public PacketDownloadHostInfo() {}
|
||||
public PacketDownloadHostInfo(String host, String id, JSONCallback callback) {
|
||||
this.host = host;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
if (host != null) json.put("host", host);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
public PacketDownloadLang() {};
|
||||
|
||||
public PacketDownloadLang(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
data.put("Updated", Calendar.getInstance().getTime().getTime());
|
||||
plugin.lang = new YAMLSection(data);
|
||||
Bukkit.getLogger().info("SubData > Lang Settings Downloaded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
private List<JSONCallback> callbacks = new ArrayList<JSONCallback>();
|
||||
|
||||
public PacketDownloadPlayerList() {}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(0).run(data);
|
||||
callbacks.remove(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
|
||||
public void callback(String id, JSONCallback callback) {
|
||||
callbacks.add(callback);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private String server;
|
||||
private String id;
|
||||
|
||||
public PacketDownloadServerInfo(String server, String id, JSONCallback callback) {
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
public PacketDownloadServerInfo() {}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("server", server);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private String host;
|
||||
private String id;
|
||||
|
||||
public PacketDownloadServerList() {}
|
||||
public PacketDownloadServerList(String host, String id, JSONCallback callback) {
|
||||
this.host = host;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
if (host != null) json.put("host", host);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.*;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketInRunEvent implements PacketIn {
|
||||
private HashMap<String, List<JSONCallback>> callbacks = new HashMap<String, List<JSONCallback>>();
|
||||
|
||||
public PacketInRunEvent() {
|
||||
callback("SubAddServerEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubAddServerEvent(UUID.fromString(json.getString("player")), json.getString("host"), json.getString("server")));
|
||||
callback("SubAddServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubCreateEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubCreateEvent(UUID.fromString(json.getString("player")), json.getString("host"), json.getString("server"),
|
||||
PacketCreateServer.ServerType.valueOf(json.getString("").toUpperCase()), new Version(json.getString("version")), json.getInt("memory"), json.getInt("port")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubSendCommandEvent(UUID.fromString(json.getString("player")), json.getString("server"), json.getString("command")));
|
||||
callback("SubSendCommandEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStartEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubStartEvent(UUID.fromString(json.getString("player")), json.getString("server")));
|
||||
callback("SubStartEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStopEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubStopEvent(UUID.fromString(json.getString("player")), json.getString("server"), json.getBoolean("force")));
|
||||
callback("SubStopEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStoppedEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubStoppedEvent(json.getString("server")));
|
||||
callback("SubStoppedEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveServerEvent", new JSONCallback() {
|
||||
@Override
|
||||
public void run(JSONObject json) {
|
||||
Bukkit.getPluginManager().callEvent(new SubRemoveServerEvent(UUID.fromString(json.getString("player")), json.getString("host"), json.getString("server")));
|
||||
callback("SubRemoveServerEvent", this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
if (callbacks.keySet().contains(data.getString("type"))) {
|
||||
List<JSONCallback> callbacks = this.callbacks.get(data.getString("type"));
|
||||
this.callbacks.remove(data.getString("type"));
|
||||
for (JSONCallback callback : callbacks) {
|
||||
callback.run(data.getJSONObject("args"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
|
||||
public void callback(String event, JSONCallback callback) {
|
||||
List<JSONCallback> callbacks = (this.callbacks.keySet().contains(event))?this.callbacks.get(event):new ArrayList<JSONCallback>();
|
||||
callbacks.add(callback);
|
||||
this.callbacks.put(event, callbacks);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class PacketInShutdown implements PacketIn {
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
if (data != null && data.keySet().contains("m")) Bukkit.getLogger().warning("SubData > Received request for a server shutdown: " + data.getString("m"));
|
||||
else Bukkit.getLogger().warning("SubData > Received request for a server shutdown");
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubDataRecieveGenericInfoEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class PacketInfoPassthrough implements PacketIn, PacketOut {
|
||||
private String t;
|
||||
private String h;
|
||||
private Version v;
|
||||
private JSONObject c;
|
||||
|
||||
public PacketInfoPassthrough() {}
|
||||
public PacketInfoPassthrough(String target, String handle, Version version, JSONObject content) {
|
||||
this.t = target;
|
||||
this.h = handle;
|
||||
this.v = version;
|
||||
this.c = content;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("t", t);
|
||||
json.put("h", h);
|
||||
json.put("v", v.toString());
|
||||
json.put("c", c);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
Bukkit.getPluginManager().callEvent(new SubDataRecieveGenericInfoEvent(data.getString("h"), new Version(data.getString("v")), data.getJSONObject("c")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
public PacketLinkServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("name", plugin.subdata.getName());
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
if (data.getInt("r") != 0) {
|
||||
Bukkit.getLogger().info("SubData > Could not link name with server: " + data.getString("m"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketStartServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String id;
|
||||
|
||||
public PacketStartServer() {}
|
||||
public PacketStartServer(String server, String id, JSONCallback callback) {
|
||||
this.player = null;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
public PacketStartServer(UUID player, String server, String id, JSONCallback callback) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
if (player != null) json.put("player", player.toString());
|
||||
json.put("server", server);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketStopServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private UUID player;
|
||||
private boolean force;
|
||||
private String server;
|
||||
private String id;
|
||||
|
||||
public PacketStopServer() {}
|
||||
public PacketStopServer(String server, boolean force, String id, JSONCallback callback) {
|
||||
this.player = null;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
public PacketStopServer(UUID player, String server, boolean force, String id, JSONCallback callback) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
if (player != null) json.put("player", player.toString());
|
||||
json.put("server", server);
|
||||
json.put("force", force);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.JSONCallback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketTeleportPlayer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, JSONCallback> callbacks = new HashMap<String, JSONCallback>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String id;
|
||||
|
||||
public PacketTeleportPlayer() {}
|
||||
public PacketTeleportPlayer(UUID player, String server, String id, JSONCallback callback) {
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject generate() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("player", player.toString());
|
||||
json.put("server", server);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JSONObject data) {
|
||||
callbacks.get(data.getString("id")).run(data);
|
||||
callbacks.remove(data.getString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* PacketIn Layout Class
|
||||
*
|
||||
* @author ME1312
|
||||
*/
|
||||
public interface PacketIn {
|
||||
/**
|
||||
* Execute Incoming Packet
|
||||
*
|
||||
* @param data Incoming Data
|
||||
*/
|
||||
void execute(JSONObject data);
|
||||
|
||||
/**
|
||||
* Get Packet Version
|
||||
*
|
||||
* @return Packet Version
|
||||
*/
|
||||
Version getVersion();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* PacketOut Layout Class
|
||||
*
|
||||
* @author ME1312
|
||||
*/
|
||||
public interface PacketOut {
|
||||
/**
|
||||
* Generate JSON Packet Contents
|
||||
*
|
||||
* @return Packet Contents
|
||||
*/
|
||||
JSONObject generate();
|
||||
|
||||
/**
|
||||
* Get Packet Version
|
||||
*
|
||||
* @return Packet Version
|
||||
*/
|
||||
Version getVersion();
|
||||
}
|
@ -0,0 +1,241 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class SubDataClient {
|
||||
private static HashMap<Class<? extends PacketOut>, String> pOut = new HashMap<Class<? extends PacketOut>, String>();
|
||||
private static HashMap<String, PacketIn> pIn = new HashMap<String, PacketIn>();
|
||||
private static boolean defaults = false;
|
||||
private PrintWriter writer;
|
||||
private Socket socket;
|
||||
private String name;
|
||||
private SubPlugin plugin;
|
||||
|
||||
/**
|
||||
* SubServers Client Instance
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param address Bind Address
|
||||
* @param port Port
|
||||
* @throws IOException
|
||||
*/
|
||||
public SubDataClient(SubPlugin plugin, String name, InetAddress address, int port) throws IOException {
|
||||
socket = new Socket(address, port);
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.writer = new PrintWriter(socket.getOutputStream(), true);
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
loop();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> sendPacket(new PacketAuthorization(plugin)), 10);
|
||||
}
|
||||
|
||||
private void loadDefaults() {
|
||||
defaults = true;
|
||||
|
||||
registerPacket(new PacketAuthorization(plugin), "Authorization");
|
||||
registerPacket(new PacketCommandServer(), "SubCommandServer");
|
||||
registerPacket(new PacketCreateServer(), "SubCreateServer");
|
||||
registerPacket(new PacketDownloadHostInfo(), "SubDownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubDownloadLang");
|
||||
registerPacket(new PacketDownloadPlayerList(), "SubDownloadPlayerList");
|
||||
registerPacket(new PacketDownloadServerInfo(), "SubDownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(), "SubDownloadServerList");
|
||||
registerPacket(new PacketInfoPassthrough(), "SubInfoPassthrough");
|
||||
registerPacket(new PacketInRunEvent(), "SubRunEvent");
|
||||
registerPacket(new PacketInShutdown(), "SubShutdown");
|
||||
registerPacket(new PacketLinkServer(plugin), "SubLinkServer");
|
||||
registerPacket(new PacketStartServer(), "SubStartServer");
|
||||
registerPacket(new PacketStopServer(), "SubStopServer");
|
||||
registerPacket(new PacketTeleportPlayer(), "SubTeleportPlayer");
|
||||
|
||||
registerPacket(PacketAuthorization.class, "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubCommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubCreateServer");
|
||||
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(PacketStartServer.class, "SubStartServer");
|
||||
registerPacket(PacketStopServer.class, "SubStopServer");
|
||||
registerPacket(PacketTeleportPlayer.class, "SubTeleportPlayer");
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
String input;
|
||||
while ((input = in.readLine()) != null) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(input);
|
||||
PacketIn packet = decodePacket(json);
|
||||
try {
|
||||
packet.execute((json.keySet().contains("c")) ? json.getJSONObject("c") : null);
|
||||
} catch (Exception e) {
|
||||
new InvocationTargetException(e, "Exception while executing PacketIn").printStackTrace();
|
||||
}
|
||||
} catch (IllegalPacketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
new IllegalPacketException("Unknown Packet Format: " + input).printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
destroy(true);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage() == null || !e.getMessage().equals("Socket closed")) e.printStackTrace();
|
||||
try {
|
||||
destroy(true);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Server Name
|
||||
*
|
||||
* @return Server Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Socket
|
||||
*
|
||||
* @return Server Socket
|
||||
*/
|
||||
public Socket getClient() {
|
||||
return socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Packet to the Network
|
||||
*
|
||||
* @param packet PacketIn to register
|
||||
* @param handle Handle to Bind
|
||||
*/
|
||||
public static void registerPacket(PacketIn packet, String handle) {
|
||||
pIn.put(handle, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Packet to the Network
|
||||
*
|
||||
* @param packet PacketOut to register
|
||||
* @param handle Handle to bind
|
||||
*/
|
||||
public static void registerPacket(Class<? extends PacketOut> packet, String handle) {
|
||||
pOut.put(packet, handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab PacketIn Instance via handle
|
||||
*
|
||||
* @param handle Handle
|
||||
* @return PacketIn
|
||||
*/
|
||||
public static PacketIn getPacket(String handle) {
|
||||
return pIn.get(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Packet to Client
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
try {
|
||||
writer.println(encodePacket(packet));
|
||||
} catch (IllegalPacketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON Encode PacketOut
|
||||
*
|
||||
* @param packet PacketOut
|
||||
* @return JSON Formatted Packet
|
||||
* @throws IllegalPacketException
|
||||
*/
|
||||
protected static JSONObject encodePacket(PacketOut packet) throws IllegalPacketException {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
if (!pOut.keySet().contains(packet.getClass())) throw new IllegalPacketException("Unknown PacketOut Channel: " + packet.getClass().getCanonicalName());
|
||||
if (packet.getVersion().toString() == null) throw new NullPointerException("PacketOut Version cannot be null: " + packet.getClass().getCanonicalName());
|
||||
|
||||
JSONObject contents = packet.generate();
|
||||
json.put("h", pOut.get(packet.getClass()));
|
||||
json.put("v", packet.getVersion().toString());
|
||||
if (contents != null) json.put("c", contents);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON Decode PacketIn
|
||||
*
|
||||
* @param json JSON to Decode
|
||||
* @return PacketIn
|
||||
* @throws IllegalPacketException
|
||||
* @throws InvocationTargetException
|
||||
*/
|
||||
protected static PacketIn decodePacket(JSONObject json) throws IllegalPacketException, InvocationTargetException {
|
||||
if (!json.keySet().contains("h") || !json.keySet().contains("v")) throw new IllegalPacketException("Unknown Packet Format: " + json.toString());
|
||||
if (!pIn.keySet().contains(json.getString("h"))) throw new IllegalPacketException("Unknown PacketIn Channel: " + json.getString("h"));
|
||||
|
||||
PacketIn packet = pIn.get(json.getString("h"));
|
||||
if (!new Version(json.getString("v")).equals(packet.getVersion())) throw new IllegalPacketException("Packet Version Mismatch in " + json.getString("h") + ": " + json.getString("v") + "->" + packet.getVersion().toString());
|
||||
return packet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops All Connections and Stops the SubData Listener
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void destroy(boolean reconnect) throws IOException {
|
||||
if (socket != null) {
|
||||
final Socket socket = this.socket;
|
||||
this.socket = null;
|
||||
if (!socket.isClosed()) socket.close();
|
||||
Bukkit.getLogger().info("SubServers > The SubData Connection was closed");
|
||||
if (reconnect) {
|
||||
Bukkit.getLogger().info("SubServers > Attempting to reconnect in 10 seconds");
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
try {
|
||||
plugin.subdata = new SubDataClient(plugin, name, socket.getInetAddress(), socket.getPort());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 10 * 20);
|
||||
}
|
||||
plugin.subdata = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class SubCommand implements CommandExecutor {
|
||||
private SubPlugin plugin;
|
||||
|
||||
public SubCommand(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
plugin.gui.getRenderer((Player) sender).newUI();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIListener;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class SubPlugin extends JavaPlugin {
|
||||
public YAMLConfig pluginconf;
|
||||
public YAMLSection lang = null;
|
||||
public SubDataClient subdata = null;
|
||||
|
||||
public UIListener gui = null;
|
||||
public final Version version = new Version("2.11.0a");
|
||||
protected Version bversion = new Version(3);
|
||||
|
||||
//public final SubAPI api = new SubAPI(this);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
Bukkit.getLogger().info("SubServers > Loading SubServers v" + version.toString() + " Libraries... ");
|
||||
getDataFolder().mkdirs();
|
||||
if (!(new UniversalFile(getDataFolder(), "config.yml").exists())) {
|
||||
copyFromJar("config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
|
||||
Bukkit.getLogger().info("SubServers > Created ~/plugins/SubServers/config.yml");
|
||||
} else if ((new Version((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.0a+"))) != 0) {
|
||||
Files.move(new UniversalFile(getDataFolder(), "config.yml").toPath(), new UniversalFile(getDataFolder(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
copyFromJar("config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
|
||||
Bukkit.getLogger().info("SubServers > Updated ~/plugins/SubServers/config.yml");
|
||||
}
|
||||
pluginconf = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
|
||||
subdata = new SubDataClient(this, pluginconf.get().getSection("Settings").getSection("SubData").getString("Name", "~no_name"),
|
||||
InetAddress.getByName(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]));
|
||||
Bukkit.getLogger().info("SubServers > SubData Connected to " + subdata.getClient().getRemoteSocketAddress().toString());
|
||||
|
||||
gui = new UIListener(this);
|
||||
getCommand("subservers").setExecutor(new SubCommand(this));
|
||||
getCommand("subservers").setAliases(Arrays.asList("sub", "subserver"));
|
||||
} catch (IOException e) {
|
||||
setEnabled(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {
|
||||
subdata.destroy(false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFromJar(String resource, String destination) {
|
||||
InputStream resStreamIn = SubPlugin.class.getClassLoader().getResourceAsStream(resource);
|
||||
File resDestFile = new File(destination);
|
||||
try {
|
||||
OutputStream resStreamOut = new FileOutputStream(resDestFile);
|
||||
int readBytes;
|
||||
byte[] buffer = new byte[4096];
|
||||
while ((readBytes = resStreamIn.read(buffer)) > 0) {
|
||||
resStreamOut.write(buffer, 0, readBytes);
|
||||
}
|
||||
resStreamOut.close();
|
||||
resStreamIn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
56
SubServers.Client/Bukkit/src/plugin.yml
Normal file
56
SubServers.Client/Bukkit/src/plugin.yml
Normal file
@ -0,0 +1,56 @@
|
||||
name: 'SubServers'
|
||||
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
|
||||
version: '2.11.0a'
|
||||
authors: [ME1312]
|
||||
softdepend: [TitleManager]
|
||||
website: 'http://www.ME1312.net/'
|
||||
commands:
|
||||
subservers:
|
||||
description: 'The SubServers Command'
|
||||
usage: /subservers help
|
||||
permissions:
|
||||
subservers.*:
|
||||
description: 'Grants Access to to Everything in SubServers.Client'
|
||||
default: op
|
||||
children:
|
||||
subserver.interface:
|
||||
description: 'Grants Access to the SubServers Interface'
|
||||
default: op
|
||||
subserver.command:
|
||||
description: 'Grants Access to the SubServers Command'
|
||||
default: op
|
||||
subservers.reload:
|
||||
description: 'Grants Access to Reload SubServers.Client'
|
||||
default: op
|
||||
subservers.host.*:
|
||||
description: 'Grants Access to SubServers Host Actions'
|
||||
default: op
|
||||
children:
|
||||
subservers.host.create.*:
|
||||
description: 'Grants Access to Create a SubServer'
|
||||
default: op
|
||||
subservers.host.edit.*:
|
||||
description: 'Grants Access to Edit a Host'
|
||||
default: op
|
||||
subservers.subserver.*:
|
||||
description: 'Grants Access to SubServers Server Actions'
|
||||
default: op
|
||||
children:
|
||||
subservers.subserver.start.*:
|
||||
description: 'Grants Access to Start a SubServer'
|
||||
default: op
|
||||
subservers.subserver.stop.*:
|
||||
description: 'Grants Access to Stop a SubServer'
|
||||
default: op
|
||||
subservers.subserver.terminate.*:
|
||||
description: 'Grants Access to Terminate a SubServer'
|
||||
default: op
|
||||
subservers.subserver.command.*:
|
||||
description: 'Grants Access to Send Commands to a SubServer'
|
||||
default: op
|
||||
subservers.subserver.edit.*:
|
||||
description: 'Grants Access to Edit a SubServer'
|
||||
default: op
|
||||
subservers.subserver.teleport.*:
|
||||
description: 'Grants Acces to Teleport to a SubServer'
|
||||
default: op
|
Loading…
Reference in New Issue
Block a user