mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
SubServers 2 Beta 5
This commit is contained in:
parent
b50452b93a
commit
83415cb873
Binary file not shown.
Binary file not shown.
@ -1,67 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.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;
|
||||
}
|
||||
}
|
@ -58,13 +58,6 @@ public abstract class Host {
|
||||
*/
|
||||
public abstract String getDirectory();
|
||||
|
||||
/**
|
||||
* Get if the Host can be Edited
|
||||
*
|
||||
* @return Editable Status
|
||||
*/
|
||||
public abstract boolean isEditable();
|
||||
|
||||
/**
|
||||
* Get the Name of this Host
|
||||
*
|
||||
@ -150,25 +143,6 @@ public abstract class Host {
|
||||
*/
|
||||
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 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
|
||||
*
|
||||
|
@ -56,11 +56,6 @@ public class InternalHost extends Host {
|
||||
return directory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -102,17 +97,6 @@ public class InternalHost extends Host {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int edit(UUID player, NamedContainer<String, ?>... changes) {
|
||||
int i = 0;
|
||||
for (NamedContainer<String, ?> change : changes) {
|
||||
switch (change.name().toLowerCase()) {
|
||||
// TODO SubEditor
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubCreator getCreator() {
|
||||
return creator;
|
||||
|
@ -471,7 +471,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
if (process2.exitValue() == 0) {
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase())) host.plugin.exServers.remove(name.toLowerCase());
|
||||
host.addSubServer(player, name, true, port, "&aThis is a SubServer", true, dir.getPath(), exec, "stop", true, false, false, false, false);
|
||||
host.addSubServer(player, name, true, port, "&aThis is a SubServer", true, new UniversalFile(".:" + name).getPath(), exec, "stop", true, false, false, false, false);
|
||||
|
||||
YAMLSection server = new YAMLSection();
|
||||
server.set("Enabled", true);
|
||||
@ -479,7 +479,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
server.set("Port", port);
|
||||
server.set("Motd", "&aThis is a SubServer");
|
||||
server.set("Log", true);
|
||||
server.set("Directory", dir.getPath());
|
||||
server.set("Directory", new UniversalFile(".:" + name));
|
||||
server.set("Executable", exec.toString());
|
||||
server.set("Stop-Command", "stop");
|
||||
server.set("Run-On-Launch", false);
|
||||
|
@ -16,7 +16,6 @@ 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;
|
||||
@ -32,7 +31,6 @@ 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);
|
||||
@ -157,182 +155,6 @@ public class InternalSubServer extends SubServer {
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitFor() throws InterruptedException {
|
||||
while (thread != null && thread.isAlive()) {
|
||||
@ -340,11 +162,6 @@ public class InternalSubServer extends SubServer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return process != null && process.isAlive();
|
||||
@ -365,11 +182,6 @@ public class InternalSubServer extends SubServer {
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable() {
|
||||
return host.isEditable() && !isRunning();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogging() {
|
||||
return log.get();
|
||||
|
@ -97,25 +97,6 @@ public abstract class SubServer extends Server {
|
||||
return command(null, command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies edits to the SubServer
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param change Change(s) to be applied
|
||||
* @return Success Status
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -151,13 +132,6 @@ public abstract class SubServer extends Server {
|
||||
*/
|
||||
public abstract void setEnabled(boolean value);
|
||||
|
||||
/**
|
||||
* Get if the SubServer can be Edited
|
||||
*
|
||||
* @return Editable Status
|
||||
*/
|
||||
public abstract boolean isEditable();
|
||||
|
||||
/**
|
||||
* If the Server is Logging
|
||||
*
|
||||
|
@ -1,6 +1,6 @@
|
||||
ip_forward: true
|
||||
network_compression_threshold: 256
|
||||
stats: undefined
|
||||
stats: 'undefined'
|
||||
permissions:
|
||||
default:
|
||||
- bungeecord.command.server
|
||||
|
@ -3,11 +3,11 @@ Settings:
|
||||
Log-Creator: true
|
||||
SubData:
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'password123'
|
||||
Password: ''
|
||||
Allowed-Connections: []
|
||||
|
||||
Hosts:
|
||||
'~Built-In':
|
||||
'~':
|
||||
Enabled: true
|
||||
Driver: 'BUILT-IN'
|
||||
Address: '127.0.0.1'
|
||||
@ -15,13 +15,13 @@ Hosts:
|
||||
Git-Bash: 'C:\Program Files\Git'
|
||||
|
||||
Servers:
|
||||
'Server_1':
|
||||
'Example':
|
||||
Enabled: false
|
||||
Host: '~Built-In'
|
||||
Port: 25566
|
||||
Host: '~'
|
||||
Port: 25567
|
||||
Motd: '&aThis is a SubServer'
|
||||
Log: true
|
||||
Directory: './Server_1'
|
||||
Directory: './Example'
|
||||
Executable: 'java -Djline.terminal=jline.UnsupportedTerminal -jar Spigot.jar'
|
||||
Stop-Command: 'stop'
|
||||
Run-On-Launch: false
|
||||
|
@ -78,8 +78,7 @@ Lang:
|
||||
'Interface.Host-Admin.Creator': '&eCreate a SubServer'
|
||||
'Interface.Host-Admin.Creator-Busy': '&4SubCreator is already running'
|
||||
'Interface.Host-Admin.SubServers': '&aView SubServers'
|
||||
'Interface.Host-Admin.Editor': '&eEdit Host'
|
||||
'Interface.Host-Admin.Editor-Unavailable': '&4This Host cannot be edited'
|
||||
'Interface.Host-Admin.Plugins': '&bPlugins...'
|
||||
'Interface.Host-Creator.Title': 'Host/$str$/Create'
|
||||
'Interface.Host-Creator.Edit-Name': 'Change Name'
|
||||
'Interface.Host-Creator.Edit-Name.Title': '&eSubCreator\n&6Enter a Name for this Server'
|
||||
@ -110,7 +109,8 @@ Lang:
|
||||
'Interface.Host-Creator.Edit-RAM.Invalid-Title': '&eSubCreator\n&cInvalid Ram Amount'
|
||||
'Interface.Host-Creator.Submit': '&eCreate SubServer'
|
||||
'Interface.Host-Creator.Form-Incomplete': '&4Buttons above must be green'
|
||||
'Interface.Host-Editor.Title': 'Host/$str$/Edit'
|
||||
'Interface.Host-Plugin.Title': 'Host/$str$/Plugins'
|
||||
'Interface.Host-Plugin.No-Plugins': '&c&oThere are No Plugins Available'
|
||||
'Interface.Host-SubServer.Title': 'Host/$str$/SubServers'
|
||||
'Interface.SubServer-Menu.Title': 'SubServer Menu'
|
||||
'Interface.SubServer-Menu.SubServer-Player-Count': '&2$int$ Player(s) Online'
|
||||
@ -130,7 +130,6 @@ Lang:
|
||||
'Interface.SubServer-Admin.Command': '&eSend a Command to the SubServer'
|
||||
'Interface.SubServer-Admin.Command.Title': '&eSubServers\n&6Enter a Command to send via Chat'
|
||||
'Interface.SubServer-Admin.Command.Message': '&eSubServers \u00BB Enter a Command to send via Chat'
|
||||
'Interface.SubServer-Admin.Teleport': '&bTeleport to Server'
|
||||
'Interface.SubServer-Admin.Editor': '&eEdit SubServer'
|
||||
'Interface.SubServer-Admin.Editor-Unavailable': '&4This SubServer cannot be edited'
|
||||
'Interface.SubServer-Editor.Title': 'SubServer/$str$/Edit'
|
||||
'Interface.SubServer-Admin.Plugins': '&bPlugins...'
|
||||
'Interface.SubServer-Plugin.Title': 'SubServer/$str$/Plugins'
|
||||
'Interface.SubServer-Plugin.No-Plugins': '&c&oThere are No Plugins Available'
|
@ -36,7 +36,6 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
info.put("name", host.getName());
|
||||
info.put("enabled", host.isEnabled());
|
||||
info.put("editable", host.isEditable());
|
||||
info.put("address", host.getAddress().toString());
|
||||
info.put("dir", host.getDirectory());
|
||||
|
||||
|
@ -34,7 +34,6 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
if (server != null && server instanceof SubServer) {
|
||||
info.put("host", ((SubServer) server).getHost().getName());
|
||||
info.put("enabled", ((SubServer) server).isEnabled() && ((SubServer) server).getHost().isEnabled());
|
||||
info.put("editable", ((SubServer) server).isEditable());
|
||||
info.put("log", ((SubServer) server).isLogging());
|
||||
info.put("dir", plugin.config.get().getSection("Servers").getSection(server.getName()).getString("Directory"));
|
||||
info.put("exec", plugin.config.get().getSection("Servers").getSection(server.getName()).getString("Executable"));
|
||||
|
@ -37,7 +37,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.2a");
|
||||
protected Version bversion = new Version(4);
|
||||
protected Version bversion = new Version(5);
|
||||
|
||||
protected boolean running = false;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
@ -98,7 +98,7 @@ public final class SubPlugin extends BungeeCord {
|
||||
} catch (NullPointerException e) {}
|
||||
brText.close();
|
||||
|
||||
if (!Version.equalsIgnoreCase("2.11.0a+")) {
|
||||
if (!Version.equalsIgnoreCase("2.11.2a+")) {
|
||||
Files.move(new UniversalFile(dir, "build.sh").toPath(), new UniversalFile(dir, "build.old" + Math.round(Math.random() * 100000) + ".sh").toPath());
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/build.sh", new UniversalFile(dir, "build.sh").getPath());
|
||||
System.out.println("SubServers > Updated ~/SubServers/build.sh");
|
||||
|
@ -2,6 +2,6 @@ Settings:
|
||||
Version: '2.11.2a+'
|
||||
Use-Title-Messages: true
|
||||
SubData:
|
||||
Name: 'Server_1'
|
||||
Name: 'undefined'
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'password123'
|
||||
Password: ''
|
@ -0,0 +1,10 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Graphic;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Renderer {
|
||||
void open(Player player, String object);
|
||||
ItemStack getIcon();
|
||||
boolean isEnabled(String object);
|
||||
}
|
@ -181,7 +181,33 @@ public class UIListener implements Listener {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').split("\\$str\\$")[0]) && // Host Plugin
|
||||
(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').split("\\$str\\$").length == 1 ||
|
||||
event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.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.hostPlugin(gui.lastPage - 1, gui.lastVistedObject);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostPlugin(gui.lastPage + 1, gui.lastVistedObject);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else {
|
||||
player.closeInventory();
|
||||
Renderer plugin = null;
|
||||
for (Renderer renderer : UIRenderer.hostPlugins.values()) {
|
||||
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin = renderer;
|
||||
}
|
||||
if (plugin == null) {
|
||||
gui.reopen();
|
||||
} else {
|
||||
plugin.open(player, gui.lastVistedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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]) &&
|
||||
@ -192,10 +218,10 @@ public class UIListener implements Listener {
|
||||
|
||||
if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverMenu(gui.lastPage - 1, null);
|
||||
gui.subserverMenu(gui.lastPage - 1, gui.lastVistedObject);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverMenu(gui.lastPage + 1, null);
|
||||
gui.subserverMenu(gui.lastPage + 1, gui.lastVistedObject);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Host-Menu", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostMenu(1);
|
||||
@ -221,14 +247,12 @@ public class UIListener implements Listener {
|
||||
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 (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.hostPlugin(1, gui.lastVistedObject);
|
||||
}
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').split("\\$str\\$")[0]) && // SubServer Admin
|
||||
@ -240,11 +264,6 @@ public class UIListener implements Listener {
|
||||
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())) {
|
||||
@ -314,14 +333,36 @@ public class UIListener implements Listener {
|
||||
}));
|
||||
});
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Teleport", '&'))) {
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&'))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.server.teleport.*") || player.hasPermission("subservers.server.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();
|
||||
gui.subserverPlugin(1, gui.lastVistedObject);
|
||||
}
|
||||
}
|
||||
} else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').split("\\$str\\$")[0]) && // SubServer Plugin
|
||||
(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').split("\\$str\\$").length == 1 ||
|
||||
event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.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.subserverPlugin(gui.lastPage - 1, gui.lastVistedObject);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.subserverPlugin(gui.lastPage + 1, gui.lastVistedObject);
|
||||
} else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else {
|
||||
player.closeInventory();
|
||||
Renderer plugin = null;
|
||||
for (Renderer renderer : UIRenderer.subserverPlugins.values()) {
|
||||
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin = renderer;
|
||||
}
|
||||
if (plugin == null) {
|
||||
gui.reopen();
|
||||
} else {
|
||||
plugin.open(player, gui.lastVistedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class UIRenderer {
|
||||
protected static HashMap<String, Renderer> hostPlugins = new HashMap<String, Renderer>();
|
||||
protected static HashMap<String, Renderer> subserverPlugins = new HashMap<String, Renderer>();
|
||||
private List<Runnable> windowHistory = new LinkedList<Runnable>();
|
||||
protected Options lastUsedOptions = null;
|
||||
protected String lastVistedObject = null;
|
||||
@ -216,6 +218,26 @@ public class UIRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Host Plugin
|
||||
*
|
||||
* @param handle Handle to bind
|
||||
* @param renderer Renderer
|
||||
*/
|
||||
public static void addHostPlugin(String handle, Renderer renderer) {
|
||||
hostPlugins.put(handle, renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add SubServer Plugin
|
||||
*
|
||||
* @param handle Handle to bind
|
||||
* @param renderer Renderer
|
||||
*/
|
||||
public static void addSubServerPlugin(String handle, Renderer renderer) {
|
||||
subserverPlugins.put(handle, renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the Host Menu
|
||||
*
|
||||
@ -384,34 +406,16 @@ public class UIRenderer {
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(1, block);
|
||||
inv.setItem(2, block);
|
||||
inv.setItem(3, block);
|
||||
inv.setItem(10, block);
|
||||
inv.setItem(11, block);
|
||||
inv.setItem(12, block);
|
||||
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.SubServers", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(2, block);
|
||||
inv.setItem(3, block);
|
||||
inv.setItem(11, block);
|
||||
inv.setItem(12, block);
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.host.edit.*") || Bukkit.getPlayer(player).hasPermission("subservers.host.edit." + host.toLowerCase()))) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Editor", '&')));
|
||||
blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.host.edit." + host.toLowerCase())));
|
||||
} else if (!json.getJSONObject("host").getBoolean("editable")) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Editor", '&')));
|
||||
blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Editor-Unavailable", '&')));
|
||||
} else {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Editor", '&'));
|
||||
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(5, block);
|
||||
inv.setItem(6, block);
|
||||
inv.setItem(7, block);
|
||||
@ -419,6 +423,17 @@ public class UIRenderer {
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
|
||||
if (!json.getJSONObject("host").getBoolean("enabled")) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&')));
|
||||
} else {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&'));
|
||||
}
|
||||
inv.setItem(27, block);
|
||||
inv.setItem(28, block);
|
||||
|
||||
if (json.getJSONObject("host").getBoolean("enabled")) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
|
||||
@ -731,37 +746,116 @@ public class UIRenderer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens Host/<name>/Edit
|
||||
* Opens Host/<name>/Plugins
|
||||
*
|
||||
* @param options Host Editor Options
|
||||
* @param host Host Name
|
||||
*/
|
||||
public void hostEditor(final HostEditorOptions options) {
|
||||
lastUsedOptions = options;
|
||||
if (!options.init()) {
|
||||
windowHistory.add(() -> hostEditor(options));
|
||||
lastVistedObject = options.getHost();
|
||||
}
|
||||
}
|
||||
public static class HostEditorOptions extends Options {
|
||||
private String host;
|
||||
public void hostPlugin(final Integer page, final String host) {
|
||||
setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", host)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, UUID.randomUUID().toString(), (json) -> {
|
||||
windowHistory.add(() -> hostPlugin(page, host));
|
||||
if (!json.getBoolean("valid")) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
setDownloading(null);
|
||||
lastVistedObject = host;
|
||||
lastPage = page;
|
||||
List<String> renderers = new ArrayList<String>();
|
||||
for (String renderer : renderers) {
|
||||
if (subserverPlugins.get(renderer).isEnabled(host)) renderers.add(renderer);
|
||||
}
|
||||
Collections.sort(renderers);
|
||||
|
||||
/**
|
||||
* Grabs a raw HostCreatorOptions instance
|
||||
*
|
||||
* @param host Host Name
|
||||
*/
|
||||
public HostEditorOptions(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15);
|
||||
ItemMeta divMeta = div.getItemMeta();
|
||||
divMeta.setDisplayName(ChatColor.RESET.toString());
|
||||
div.setItemMeta(divMeta);
|
||||
|
||||
/**
|
||||
* Gets the Host Name
|
||||
*
|
||||
* @return Host Name
|
||||
*/
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
int i = 0;
|
||||
int min = ((page - 1) * 36);
|
||||
int max = (min + 35);
|
||||
int count = (renderers.size() == 0)?27:((renderers.size() - min - 1 >= max)?36:renderers.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", host));
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
block.setItemMeta(divMeta);
|
||||
while (i < area) {
|
||||
inv.setItem(i, block);
|
||||
i++;
|
||||
}
|
||||
ItemStack adiv = block;
|
||||
i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0);
|
||||
|
||||
boolean even = (count & 1) == 0 && count < 9;
|
||||
|
||||
for (String renderer : renderers) {
|
||||
if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) {
|
||||
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
|
||||
|
||||
inv.setItem(i, hostPlugins.get(renderer).getIcon());
|
||||
|
||||
count--;
|
||||
if (count < 9 && (i == 8 || i == 17 || i == 26)) {
|
||||
i += (int) Math.floor((9 - count) / 2) + 1;
|
||||
even = (count & 1) == 0;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (renderers.size() == 0) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.No-Plugins", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(12, block);
|
||||
inv.setItem(13, block);
|
||||
inv.setItem(14, block);
|
||||
}
|
||||
|
||||
i = inv.getSize() - 18;
|
||||
while (i < inv.getSize()) {
|
||||
inv.setItem(i, div);
|
||||
i++;
|
||||
}
|
||||
i = inv.getSize() - 9;
|
||||
|
||||
if (min != 0) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
} else i += 2;
|
||||
i++;
|
||||
if (hasHistory()) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
i++;
|
||||
}
|
||||
if (renderers.size() - 1 > max) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i, block);
|
||||
}
|
||||
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -994,20 +1088,6 @@ public class UIRenderer {
|
||||
inv.setItem(14, block);
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.server.teleport.*") || Bukkit.getPlayer(player).hasPermission("subservers.server.teleport." + subserver.toLowerCase()))) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Teleport", '&')));
|
||||
blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.server.teleport." + subserver.toLowerCase())));
|
||||
} else {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Teleport", '&'));
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(27, block);
|
||||
inv.setItem(28, block);
|
||||
} else {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.start.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.start." + subserver.toLowerCase()))) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
@ -1024,38 +1104,27 @@ public class UIRenderer {
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'));
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(1, block);
|
||||
inv.setItem(2, block);
|
||||
inv.setItem(3, block);
|
||||
inv.setItem(10, block);
|
||||
inv.setItem(11, block);
|
||||
inv.setItem(12, block);
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.edit.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.edit." + subserver.toLowerCase()))) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Editor", '&')));
|
||||
blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Invalid-Permission", '&').replace("$str$", "subservers.subserver.edit." + subserver.toLowerCase())));
|
||||
} else if (!json.getJSONObject("server").getBoolean("editable")) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Editor", '&')));
|
||||
blockMeta.setLore(Arrays.asList(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Editor-Unavailable", '&')));
|
||||
} else {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Editor", '&'));
|
||||
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(4, block);
|
||||
inv.setItem(5, block);
|
||||
inv.setItem(6, block);
|
||||
inv.setItem(7, block);
|
||||
inv.setItem(12, block);
|
||||
inv.setItem(13, block);
|
||||
inv.setItem(14, block);
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
}
|
||||
|
||||
if (!json.getJSONObject("server").getBoolean("enabled")) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&')));
|
||||
} else {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&'));
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(27, block);
|
||||
inv.setItem(28, block);
|
||||
|
||||
if (json.getJSONObject("server").getBoolean("temp")) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 11);
|
||||
blockMeta = block.getItemMeta();
|
||||
@ -1099,38 +1168,115 @@ public class UIRenderer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens SubServer/<name>/Edit
|
||||
* Opens SubServer/<name>/Plugins
|
||||
*
|
||||
* @param options SubServerEditorOptions
|
||||
* @param subserver SubServer Name
|
||||
*/
|
||||
public void subserverEditor(final SubServerEditorOptions options) {
|
||||
lastUsedOptions = options;
|
||||
if (!options.init()) {
|
||||
windowHistory.add(() -> subserverEditor(options));
|
||||
lastVistedObject = options.getSubserver();
|
||||
}
|
||||
}
|
||||
public static class SubServerEditorOptions extends Options {
|
||||
private List<Runnable> history = new LinkedList<Runnable>();
|
||||
private String subserver;
|
||||
private boolean init = false;
|
||||
public void subserverPlugin(final Integer page, final String subserver) {
|
||||
setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", subserver)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, UUID.randomUUID().toString(), json -> {
|
||||
windowHistory.add(() -> subserverPlugin(page, subserver));
|
||||
if (!json.getString("type").equals("subserver")) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
setDownloading(null);
|
||||
lastVistedObject = subserver;
|
||||
lastPage = page;
|
||||
List<String> renderers = new ArrayList<String>();
|
||||
for (String renderer : renderers) {
|
||||
if (subserverPlugins.get(renderer).isEnabled(subserver)) renderers.add(renderer);
|
||||
}
|
||||
Collections.sort(renderers);
|
||||
|
||||
/**
|
||||
* Grabs a raw SubServerEditorOptions instance
|
||||
*
|
||||
* @param subserver SubServer Name
|
||||
*/
|
||||
public SubServerEditorOptions(String subserver) {
|
||||
this.subserver = subserver;
|
||||
}
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15);
|
||||
ItemMeta divMeta = div.getItemMeta();
|
||||
divMeta.setDisplayName(ChatColor.RESET.toString());
|
||||
div.setItemMeta(divMeta);
|
||||
|
||||
/**
|
||||
* Gets the SubServer Name
|
||||
*
|
||||
* @return SubServer Name
|
||||
*/
|
||||
public String getSubserver() {
|
||||
return this.subserver;
|
||||
}
|
||||
int i = 0;
|
||||
int min = ((page - 1) * 36);
|
||||
int max = (min + 35);
|
||||
int count = (renderers.size() == 0)?27:((renderers.size() - min - 1 >= max)?36:renderers.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", subserver));
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
|
||||
block.setItemMeta(divMeta);
|
||||
while (i < area) {
|
||||
inv.setItem(i, block);
|
||||
i++;
|
||||
}
|
||||
ItemStack adiv = block;
|
||||
i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0);
|
||||
|
||||
boolean even = (count & 1) == 0 && count < 9;
|
||||
|
||||
for (String renderer : renderers) {
|
||||
if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) {
|
||||
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
|
||||
|
||||
inv.setItem(i, subserverPlugins.get(renderer).getIcon());
|
||||
|
||||
count--;
|
||||
if (count < 9 && (i == 8 || i == 17 || i == 26)) {
|
||||
i += (int) Math.floor((9 - count) / 2) + 1;
|
||||
even = (count & 1) == 0;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (renderers.size() == 0) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.No-Plugins", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(12, block);
|
||||
inv.setItem(13, block);
|
||||
inv.setItem(14, block);
|
||||
}
|
||||
|
||||
i = inv.getSize() - 18;
|
||||
while (i < inv.getSize()) {
|
||||
inv.setItem(i, div);
|
||||
i++;
|
||||
}
|
||||
i = inv.getSize() - 9;
|
||||
|
||||
if (min != 0) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
} else i += 2;
|
||||
i++;
|
||||
if (hasHistory()) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
i++;
|
||||
}
|
||||
if (renderers.size() - 1 > max) {
|
||||
block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'));
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i, block);
|
||||
}
|
||||
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
@ -181,6 +181,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Start.Running", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Start", '&'));
|
||||
break;
|
||||
default:
|
||||
@ -211,6 +212,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Stop.Not-Running", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Stop", '&'));
|
||||
break;
|
||||
default:
|
||||
@ -240,6 +242,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Terminate.Not-Running", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Terminate", '&'));
|
||||
break;
|
||||
default:
|
||||
@ -278,6 +281,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Command.Not-Running", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Command", '&'));
|
||||
break;
|
||||
default:
|
||||
@ -326,6 +330,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Creator.Invalid-Memory", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Creator", '&'));
|
||||
break;
|
||||
default:
|
||||
@ -356,8 +361,8 @@ public final class SubCommand implements CommandExecutor {
|
||||
case "host/creator":
|
||||
if (sender.hasPermission("subservers.host.create.*") || sender.hasPermission("subservers.host.create." + args[2].toLowerCase())) plugin.gui.getRenderer((Player) sender).hostCreator(new UIRenderer.CreatorOptions(args[2]));
|
||||
break;
|
||||
case "host/editor":
|
||||
if (sender.hasPermission("subservers.host.edit.*") || sender.hasPermission("subservers.host.edit." + args[2].toLowerCase())) plugin.gui.getRenderer((Player) sender).hostEditor(new UIRenderer.HostEditorOptions(args[2]));
|
||||
case "host/plugins":
|
||||
plugin.gui.getRenderer((Player) sender).hostPlugin(Integer.parseInt(args[2]), args[3]);
|
||||
break;
|
||||
case "subserver":
|
||||
if (args.length > 3) plugin.gui.getRenderer((Player) sender).subserverMenu(Integer.parseInt(args[2]), args[3]);
|
||||
@ -367,8 +372,8 @@ public final class SubCommand implements CommandExecutor {
|
||||
case "subserver/":
|
||||
plugin.gui.getRenderer((Player) sender).subserverAdmin(args[2]);
|
||||
break;
|
||||
case "subserver/editor":
|
||||
if (sender.hasPermission("subservers.subserver.edit.*") || sender.hasPermission("subservers.subserver.edit." + args[2].toLowerCase())) plugin.gui.getRenderer((Player) sender).subserverEditor(new UIRenderer.SubServerEditorOptions(args[2]));
|
||||
case "subserver/plugins":
|
||||
plugin.gui.getRenderer((Player) sender).subserverPlugin(Integer.parseInt(args[2]), args[3]);
|
||||
break;
|
||||
}
|
||||
} catch (Throwable e) {}
|
||||
@ -398,6 +403,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Teleport.Offline", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Teleport", '&'));
|
||||
break;
|
||||
default:
|
||||
@ -425,6 +431,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Teleport.Offline", '&'));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Teleport", '&'));
|
||||
break;
|
||||
default:
|
||||
|
@ -4,6 +4,7 @@ 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.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -21,7 +22,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
|
||||
public UIListener gui = null;
|
||||
public Version version;
|
||||
protected Version bversion = new Version(4);
|
||||
protected Version bversion = new Version(5);
|
||||
|
||||
//public final SubAPI api = new SubAPI(this);
|
||||
|
||||
@ -32,12 +33,12 @@ public final class SubPlugin extends JavaPlugin {
|
||||
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());
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "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());
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "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"));
|
||||
@ -65,21 +66,4 @@ public final class SubPlugin extends JavaPlugin {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user