Allow commands to be sent to external servers

This commit is contained in:
ME1312 2021-12-01 04:50:25 -05:00
parent aef7a164e6
commit 7179911d4c
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
60 changed files with 908 additions and 555 deletions

View File

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId> <artifactId>GalaxiUtil</artifactId>
<version>21w47d</version> <version>21w49a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Bungee.Event; package net.ME1312.SubServers.Bungee.Event;
import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Host.SubServer; import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.SubServers.Bungee.Library.SubEvent; import net.ME1312.SubServers.Bungee.Library.SubEvent;
import net.md_5.bungee.api.plugin.Cancellable; import net.md_5.bungee.api.plugin.Cancellable;
@ -15,20 +15,24 @@ import java.util.UUID;
public class SubSendCommandEvent extends Event implements SubEvent, Cancellable { public class SubSendCommandEvent extends Event implements SubEvent, Cancellable {
private boolean cancelled = false; private boolean cancelled = false;
private UUID player; private UUID player;
private SubServer server; private Server server;
private String command; private String command;
private UUID target;
/** /**
* Server Command Event * Server Command Event
* *
* @param player Player Commanding Server * @param player Player Commanding
* @param server Server being Commanded * @param server Target Server
* @param command Command to Send
* @param target Player that will send
*/ */
public SubSendCommandEvent(UUID player, SubServer server, String command) { public SubSendCommandEvent(UUID player, Server server, String command, UUID target) {
Util.nullpo(server, command); Util.nullpo(server, command);
this.player = player; this.player = player;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.target = target;
} }
/** /**
@ -36,7 +40,7 @@ public class SubSendCommandEvent extends Event implements SubEvent, Cancellable
* *
* @return The Server Effected * @return The Server Effected
*/ */
public SubServer getServer() { return server; } public Server getServer() { return server; }
/** /**
* Gets the player that triggered the Event * Gets the player that triggered the Event
@ -63,6 +67,15 @@ public class SubSendCommandEvent extends Event implements SubEvent, Cancellable
command = value; command = value;
} }
/**
* Gets the Player that will be forced to send the Command
*
* @return Target Player or null if Console
*/
public UUID getTarget() {
return target;
}
/** /**
* Gets the Cancelled Status * Gets the Cancelled Status
* *

View File

@ -214,7 +214,7 @@ public class ExternalSubServer extends SubServerImpl {
public boolean command(UUID player, String command) { public boolean command(UUID player, String command) {
Util.nullpo(command); Util.nullpo(command);
if (running) { if (running) {
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command); SubSendCommandEvent event = new SubSendCommandEvent(player, this, command, null);
host.plugin.getPluginManager().callEvent(event); host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) { if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) {
history.add(new LoggedCommand(player, event.getCommand())); history.add(new LoggedCommand(player, event.getCommand()));

View File

@ -278,7 +278,7 @@ public class InternalSubServer extends SubServerImpl {
public boolean command(UUID player, String command) { public boolean command(UUID player, String command) {
Util.nullpo(command); Util.nullpo(command);
if (thread != null && thread.isAlive()) { if (thread != null && thread.isAlive()) {
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command); SubSendCommandEvent event = new SubSendCommandEvent(player, this, command, null);
host.plugin.getPluginManager().callEvent(event); host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) { if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) {
try { try {

View File

@ -58,6 +58,34 @@ public interface Server extends ServerInfo, ClientHandler, ExtraDataHandler<Stri
*/ */
void removeGroup(String value); void removeGroup(String value);
/**
* Commands the Server
*
* @param player Player who's Commanding
* @param target Player who will Send
* @param command Command to Send
*/
boolean command(UUID player, UUID target, String command);
/**
* Commands the Server
*
* @param player Player who's Commanding
* @param command Command to Send
*/
default boolean command(UUID player, String command) {
return command(player, null, command);
}
/**
* Commands the Server
*
* @param command Command to Send
*/
default boolean command(String command) {
return command(null, command);
}
/** /**
* Get players on this server across all known proxies * Get players on this server across all known proxies
* *

View File

@ -5,15 +5,20 @@ import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.DataClient; import net.ME1312.SubData.Server.DataClient;
import net.ME1312.SubData.Server.SubDataClient; import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.SubSendCommandEvent;
import net.ME1312.SubServers.Bungee.Host.SubServer.LoggedCommand;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException; import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExControlPlayer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer; import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer.Edit; import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer.Edit;
import net.ME1312.SubServers.Bungee.SubAPI; import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.BungeeServerInfo; import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.*; import java.util.*;
@ -173,6 +178,20 @@ public class ServerImpl extends BungeeServerInfo implements Server {
Collections.sort(groups); Collections.sort(groups);
} }
@Override
public boolean command(UUID player, UUID target, String command) {
Util.nullpo(command);
SubDataClient channel = (SubDataClient) getSubData()[0];
if (channel != null) {
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command, target);
ProxyServer.getInstance().getPluginManager().callEvent(event);
if (!event.isCancelled() && (player == null || !SubServerImpl.DISALLOWED_COMMANDS.matcher(command).find())) {
channel.sendPacket(new PacketExControlPlayer(target, command));
return true;
} else return false;
} else return false;
}
@Override @Override
public Collection<RemotePlayer> getRemotePlayers() { public Collection<RemotePlayer> getRemotePlayers() {
return SubAPI.getInstance().getRemotePlayers(this).values(); return SubAPI.getInstance().getRemotePlayers(this).values();

View File

@ -3,6 +3,7 @@ package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Map.ObjectMap; import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Util;
import java.io.File;
import java.util.*; import java.util.*;
/** /**
@ -114,7 +115,9 @@ public interface SubServer extends Server {
* *
* @return Success Status * @return Success Status
*/ */
boolean start(); default boolean start() {
return start(null);
}
/** /**
* Stops the Server * Stops the Server
@ -129,7 +132,9 @@ public interface SubServer extends Server {
* *
* @return Success Status * @return Success Status
*/ */
boolean stop(); default boolean stop() {
return stop(null);
}
/** /**
* Terminates the Server * Terminates the Server
@ -144,24 +149,9 @@ public interface SubServer extends Server {
* *
* @return Success Status * @return Success Status
*/ */
boolean terminate(); default boolean terminate() {
return terminate(null);
/** }
* Commands the Server
*
* @param player Player who Commanded
* @param command Command to Send
* @return Success Status
*/
boolean command(UUID player, String command);
/**
* Commands the Server
*
* @param command Command to Send
* @return Success Status
*/
boolean command(String command);
/** /**
* Edits the Server * Edits the Server
@ -325,7 +315,9 @@ public interface SubServer extends Server {
* *
* @return Full Server Directory Path * @return Full Server Directory Path
*/ */
String getFullPath(); default String getFullPath() {
return new File(getHost().getPath(), getPath()).getPath();
}
/** /**
* Get the Server's Executable String * Get the Server's Executable String

View File

@ -231,7 +231,7 @@ public abstract class SubServerController {
/** /**
* Commands the Server * Commands the Server
* *
* @param player Player who Commanded * @param player Player who's Commanding
* @param command Command to Send * @param command Command to Send
* @return Success Status * @return Success Status
*/ */

View File

@ -58,26 +58,6 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
super(name, new InetSocketAddress(host.getAddress().getHostAddress(), port), motd, hidden, restricted); super(name, new InetSocketAddress(host.getAddress().getHostAddress(), port), motd, hidden, restricted);
} }
@Override
public boolean start() {
return start(null);
}
@Override
public boolean stop() {
return stop(null);
}
@Override
public boolean terminate() {
return terminate(null);
}
@Override
public boolean command(String command) {
return command(null, command);
}
public int edit(UUID player, ObjectMap<String> edit) { public int edit(UUID player, ObjectMap<String> edit) {
return edit(player, edit, false); return edit(player, edit, false);
} }
@ -136,11 +116,6 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
} }
} }
@Override
public String getFullPath() {
return new File(getHost().getPath(), getPath()).getPath();
}
@Override @Override
public void toggleCompatibility(SubServer... server) { public void toggleCompatibility(SubServer... server) {
for (SubServer s : server) { for (SubServer s : server) {

View File

@ -309,7 +309,7 @@ public class ConfigUpdater {
if (was.compareTo(new Version("19w22b")) <= 0) { if (was.compareTo(new Version("19w22b")) <= 0) {
if (existing.contains("Lang")) { if (existing.contains("Lang")) {
updated.getMap("Lang").remove("Interface.Host-Admin.SubServers"); updated.getMap("Lang").remove("Interface.Host-Admin.SubServers");
updated.getMap("Lang").remove("Interface.SubServer-Admin.Command"); updated.getMap("Lang").remove("Interface.Server-Admin.Command");
} }
existing = updated.clone(); existing = updated.clone();
@ -324,7 +324,7 @@ public class ConfigUpdater {
existing = updated.clone(); existing = updated.clone();
i++; i++;
} if (was.compareTo(new Version("21w27b")) <= 0) { } if (was.compareTo(new Version("21w49b")) <= 0) {
//existing = updated.clone(); //existing = updated.clone();
i++; i++;
@ -430,9 +430,10 @@ public class ConfigUpdater {
def.put("Command.Terminate", "&aSubServers &2&l\\u00BB&a Terminated &2$int$&a subserver(s)"); def.put("Command.Terminate", "&aSubServers &2&l\\u00BB&a Terminated &2$int$&a subserver(s)");
def.put("Command.Terminate.Disappeared", "&cSubServers &4&l\\u00BB&c Subserver &4$str$&c has disappeared"); def.put("Command.Terminate.Disappeared", "&cSubServers &4&l\\u00BB&c Subserver &4$str$&c has disappeared");
def.put("Command.Terminate.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 subserver(s) were already offline"); def.put("Command.Terminate.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 subserver(s) were already offline");
def.put("Command.Command", "&aSubServers &2&l\\u00BB&a Sent command to &2$int$&a subserver(s)"); def.put("Command.Command", "&aSubServers &2&l\\u00BB&a Sent command to &2$int$&a server(s)");
def.put("Command.Command.Disappeared", "&cSubServers &4&l\\u00BB&c Server &4$str$&c has disappeared");
def.put("Command.Command.No-Command", "&cSubServers &4&l\\u00BB&c No command was entered"); def.put("Command.Command.No-Command", "&cSubServers &4&l\\u00BB&c No command was entered");
def.put("Command.Command.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 subserver(s) were offline"); def.put("Command.Command.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 server(s) were unavailable");
def.put("Command.Creator", "&aSubServers &2&l\\u00BB&a Creating subserver &2$str$&a"); def.put("Command.Creator", "&aSubServers &2&l\\u00BB&a Creating subserver &2$str$&a");
def.put("Command.Creator.Exists", "&cSubServers &4&l\\u00BB&c There is already a subserver with that name"); def.put("Command.Creator.Exists", "&cSubServers &4&l\\u00BB&c There is already a subserver with that name");
def.put("Command.Creator.Unknown-Host", "&cSubServers &4&l\\u00BB&c There is no host with that name"); def.put("Command.Creator.Unknown-Host", "&cSubServers &4&l\\u00BB&c There is no host with that name");
@ -520,24 +521,23 @@ public class ConfigUpdater {
def.put("Interface.Server-Menu.SubServer-Incompatible", "&4Incompatible with $str$"); def.put("Interface.Server-Menu.SubServer-Incompatible", "&4Incompatible with $str$");
def.put("Interface.Server-Menu.SubServer-Unavailable", "&4Unavailable"); def.put("Interface.Server-Menu.SubServer-Unavailable", "&4Unavailable");
def.put("Interface.Server-Menu.SubServer-Disabled", "&4Disabled"); def.put("Interface.Server-Menu.SubServer-Disabled", "&4Disabled");
def.put("Interface.Server-Menu.SubServer-Invalid", "&4Cannot be managed by SubServers");
def.put("Interface.Server-Menu.No-Servers", "&c&oThere are No Servers"); def.put("Interface.Server-Menu.No-Servers", "&c&oThere are No Servers");
def.put("Interface.Server-Menu.Host-Menu", "&b&lView Hosts"); def.put("Interface.Server-Menu.Host-Menu", "&b&lView Hosts");
def.put("Interface.SubServer-Admin.Title", "SubServer/$str$"); def.put("Interface.Server-Admin.Title", "Server/$str$");
def.put("Interface.SubServer-Admin.Start", "&aStart SubServer"); def.put("Interface.Server-Admin.Start", "&aStart SubServer");
def.put("Interface.SubServer-Admin.Start.Title", "&aStarting SubServer"); def.put("Interface.Server-Admin.Start.Title", "&aStarting SubServer");
def.put("Interface.SubServer-Admin.Stop", "&cStop SubServer"); def.put("Interface.Server-Admin.Stop", "&cStop SubServer");
def.put("Interface.SubServer-Admin.Stop.Title", "&cStopping $str$"); def.put("Interface.Server-Admin.Stop.Title", "&cStopping $str$");
def.put("Interface.SubServer-Admin.Terminate", "&4Terminate SubServer"); def.put("Interface.Server-Admin.Terminate", "&4Terminate SubServer");
def.put("Interface.SubServer-Admin.Terminate.Title", "&cTerminating $str$"); def.put("Interface.Server-Admin.Terminate.Title", "&cTerminating $str$");
def.put("Interface.SubServer-Admin.Command", "&bSend a Command to the SubServer"); def.put("Interface.Server-Admin.Command", "&bSend a Command to the Server");
def.put("Interface.SubServer-Admin.Command.Title", "&eSubServers\\n&6Enter a Command to send via Chat"); def.put("Interface.Server-Admin.Command.Title", "&eSubServers\\n&6Enter a Command to send via Chat");
def.put("Interface.SubServer-Admin.Command.Message", "&eSubServers &6&l\\u00BB&e Enter a Command to send via Chat"); def.put("Interface.Server-Admin.Command.Message", "&eSubServers &6&l\\u00BB&e Enter a Command to send via Chat");
def.put("Interface.SubServer-Admin.Update", "&eUpdate SubServer"); def.put("Interface.Server-Admin.Update", "&eUpdate SubServer");
def.put("Interface.SubServer-Admin.Update.Title", "&eSubServers\\n&6Enter a Server Version to update to"); def.put("Interface.Server-Admin.Update.Title", "&eSubServers\\n&6Enter a Server Version to update to");
def.put("Interface.SubServer-Admin.Update.Message", "&eSubServers &6&l\\u00BB&e Enter a Server Version to update to via Chat"); def.put("Interface.Server-Admin.Update.Message", "&eSubServers &6&l\\u00BB&e Enter a Server Version to update to via Chat");
def.put("Interface.SubServer-Admin.Plugins", "&bPlugins..."); def.put("Interface.Server-Admin.Plugins", "&bPlugins...");
def.put("Interface.SubServer-Plugin.Title", "SubServer/$str$/Plugins"); def.put("Interface.SubServer-Plugin.Title", "Server/$str$/Plugins");
def.put("Interface.SubServer-Plugin.No-Plugins", "&c&oThere are No Plugins Available"); def.put("Interface.SubServer-Plugin.No-Plugins", "&c&oThere are No Plugins Available");
YAMLSection lang = new YAMLSection(); YAMLSection lang = new YAMLSection();

View File

@ -51,27 +51,28 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
@Override @Override
public void receive(SubDataClient client, ObjectMap<Integer> data) { public void receive(SubDataClient client, ObjectMap<Integer> data) {
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null); UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
try { try {
String server = data.getString(0x0001); String server = data.getString(0x0001);
String command = data.getString(0x0002); String command = data.getString(0x0002);
UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null); UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null);
UUID target = (data.contains(0x0004)?data.getUUID(0x0004):null);
Map<String, Server> servers = plugin.api.getServers(); Map<String, Server> servers = plugin.api.getServers();
if (!server.equals("*") && !servers.keySet().contains(server.toLowerCase())) { if (!server.equals("*") && !servers.keySet().contains(server.toLowerCase())) {
client.sendPacket(new PacketCommandServer(3, tracker)); client.sendPacket(new PacketCommandServer(3, tracker));
} else if (!server.equals("*") && !(servers.get(server.toLowerCase()) instanceof SubServer)) { } else if (!server.equals("*") && !(target == null && servers.get(server.toLowerCase()) instanceof SubServer) && servers.get(server.toLowerCase()).getSubData()[0] == null) {
client.sendPacket(new PacketCommandServer(4, tracker)); client.sendPacket(new PacketCommandServer(4, tracker));
} else if (!server.equals("*") && !((SubServer) servers.get(server.toLowerCase())).isRunning()) { } else if (!server.equals("*") && servers.get(server.toLowerCase()) instanceof SubServer && !((SubServer) servers.get(server.toLowerCase())).isRunning()) {
client.sendPacket(new PacketCommandServer(5, tracker)); client.sendPacket(new PacketCommandServer(5, tracker));
} else { } else {
if (server.equals("*")) { if (server.equals("*")) {
boolean sent = false; boolean sent = false;
for (Server next : servers.values()) { for (Server next : servers.values()) {
if (next instanceof SubServer && ((SubServer) next).isRunning()) { if (target == null) {
if (((SubServer) next).command(player, command)) { sent |= next.command(player, command);
sent = true; } else {
} sent |= next.command(player, target, command);
} }
} }
if (sent) { if (sent) {
@ -80,10 +81,10 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
client.sendPacket(new PacketCommandServer(1, tracker)); client.sendPacket(new PacketCommandServer(1, tracker));
} }
} else { } else {
if (((SubServer) servers.get(server.toLowerCase())).command(player, command)) { if (target == null) {
client.sendPacket(new PacketCommandServer(0, tracker)); client.sendPacket(new PacketCommandServer((servers.get(server.toLowerCase()).command(player, command))? 0 : 1, tracker));
} else { } else {
client.sendPacket(new PacketCommandServer(1, tracker)); client.sendPacket(new PacketCommandServer((servers.get(server.toLowerCase()).command(player, target, command))? 0 : 1, tracker));
} }
} }
} }

View File

@ -60,7 +60,7 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
data.set(0x0005, directory); data.set(0x0005, directory);
data.set(0x0006, executable); data.set(0x0006, executable);
data.set(0x0007, stopcmd); data.set(0x0007, stopcmd);
if (running != null) data.set(0x0008, running.toString()); if (running != null) data.set(0x0008, running);
return data; return data;
} }

View File

@ -0,0 +1,62 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
/**
* External Player Control Packet
*/
public class PacketExControlPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private String command;
private UUID target;
private UUID tracker;
/**
* New PacketExControlPlayer (In)
*/
public PacketExControlPlayer() {}
/**
* New PacketExControlPlayer (Out)
*
* @param target Target Player
* @param command Command to send
* @param callback Callbacks
*/
@SafeVarargs
public PacketExControlPlayer(UUID target, String command, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(command, callback);
this.target = target;
this.command = command;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
callbacks.put(tracker, callback);
}
@Override
public ObjectMap<Integer> send(SubDataClient client) {
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, command);
if (target != null) data.set(0x0002, target);
return data;
}
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}
@Override
public int version() {
return 0x0001;
}
}

View File

@ -86,7 +86,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubAddHostEvent event) { public void event(SubAddHostEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("host", event.getHost().getName()); args.set("host", event.getHost().getName());
broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args)); broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args));
} }
@ -96,7 +96,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubAddServerEvent event) { public void event(SubAddServerEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
if (event.getHost() != null) args.set("host", event.getHost().getName()); if (event.getHost() != null) args.set("host", event.getHost().getName());
args.set("server", event.getServer().getName()); args.set("server", event.getServer().getName());
broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args)); broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args));
@ -107,7 +107,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubCreateEvent event) { public void event(SubCreateEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("update", event.isUpdate()); args.set("update", event.isUpdate());
args.set("name", event.getName()); args.set("name", event.getName());
args.set("host", event.getHost().getName()); args.set("host", event.getHost().getName());
@ -121,7 +121,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
@EventHandler(priority = Byte.MAX_VALUE) @EventHandler(priority = Byte.MAX_VALUE)
public void event(SubCreatedEvent event) { public void event(SubCreatedEvent event) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("success", event.wasSuccessful()); args.set("success", event.wasSuccessful());
args.set("update", event.wasUpdate()); args.set("update", event.wasUpdate());
args.set("name", event.getName()); args.set("name", event.getName());
@ -136,9 +136,10 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubSendCommandEvent event) { public void event(SubSendCommandEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("server", event.getServer().getName()); args.set("server", event.getServer().getName());
args.set("command", event.getCommand()); args.set("command", event.getCommand());
if (event.getTarget() != null) args.set("target", event.getTarget());
broadcast(new PacketOutExRunEvent(event.getClass(), args)); broadcast(new PacketOutExRunEvent(event.getClass(), args));
} }
} }
@ -147,7 +148,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubEditServerEvent event) { public void event(SubEditServerEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("server", event.getServer().getName()); args.set("server", event.getServer().getName());
args.set("edit", event.getEdit().key()); args.set("edit", event.getEdit().key());
args.set("value", event.getEdit().value().asObject()); args.set("value", event.getEdit().value().asObject());
@ -159,7 +160,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubStartEvent event) { public void event(SubStartEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("server", event.getServer().getName()); args.set("server", event.getServer().getName());
broadcast(new PacketOutExRunEvent(event.getClass(), args)); broadcast(new PacketOutExRunEvent(event.getClass(), args));
} }
@ -176,7 +177,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubStopEvent event) { public void event(SubStopEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("server", event.getServer().getName()); args.set("server", event.getServer().getName());
args.set("force", event.isForced()); args.set("force", event.isForced());
broadcast(new PacketOutExRunEvent(event.getClass(), args)); broadcast(new PacketOutExRunEvent(event.getClass(), args));
@ -195,7 +196,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubRemoveServerEvent event) { public void event(SubRemoveServerEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
if (event.getHost() != null) args.set("host", event.getHost().getName()); if (event.getHost() != null) args.set("host", event.getHost().getName());
args.set("server", event.getServer().getName()); args.set("server", event.getServer().getName());
broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args)); broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args));
@ -206,7 +207,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
public void event(SubRemoveHostEvent event) { public void event(SubRemoveHostEvent event) {
if (!event.isCancelled()) { if (!event.isCancelled()) {
ObjectMap<String> args = new ObjectMap<String>(); ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); if (event.getPlayer() != null) args.set("player", event.getPlayer());
args.set("host", event.getHost().getName()); args.set("host", event.getHost().getName());
broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args)); broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args));
} }

View File

@ -68,44 +68,28 @@ public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOu
boolean sent = false; boolean sent = false;
if (force) { if (force) {
for (Server server : servers.values()) { for (Server server : servers.values()) {
if (server instanceof SubServer && ((SubServer) server).isRunning()) { if (server instanceof SubServer) {
if (((SubServer) server).terminate(player)) { sent |= ((SubServer) server).terminate(player);
sent = true;
}
} }
} }
if (sent) {
client.sendPacket(new PacketStopServer(0, tracker));
} else {
client.sendPacket(new PacketStopServer(1, tracker));
}
} else { } else {
for (Server server : servers.values()) { for (Server server : servers.values()) {
if (server instanceof SubServer && ((SubServer) server).isRunning()) { if (server instanceof SubServer) {
if (((SubServer) server).stop(player)) { sent |= ((SubServer) server).stop(player);
sent = true;
}
} }
} }
if (sent) { }
client.sendPacket(new PacketStopServer(0, tracker));
} else { if (sent) {
client.sendPacket(new PacketStopServer(1, tracker)); client.sendPacket(new PacketStopServer(0, tracker));
} } else {
client.sendPacket(new PacketStopServer(1, tracker));
} }
} else { } else {
if (force) { if (force) {
if (((SubServer) servers.get(name.toLowerCase())).terminate(player)) { client.sendPacket(new PacketStopServer((((SubServer) servers.get(name.toLowerCase())).terminate(player))? 0 : 1, tracker));
client.sendPacket(new PacketStopServer(0, tracker));
} else {
client.sendPacket(new PacketStopServer(1, tracker));
}
} else { } else {
if (((SubServer) servers.get(name.toLowerCase())).stop(player)) { client.sendPacket(new PacketStopServer((((SubServer) servers.get(name.toLowerCase())).stop(player))? 0 : 1, tracker));
client.sendPacket(new PacketStopServer(0, tracker));
} else {
client.sendPacket(new PacketStopServer(1, tracker));
}
} }
} }
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -27,7 +27,7 @@ public class SubProtocol extends SubDataProtocol {
SubProxy plugin = SubAPI.getInstance().getInternals(); SubProxy plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2"); setName("SubServers 2");
setVersion(new Version("2.16a+")); setVersion(new Version("2.18a+"));
// 00-0F: Object Link Packets // 00-0F: Object Link Packets
@ -129,6 +129,7 @@ public class SubProtocol extends SubDataProtocol {
registerPacket(0x0075, PacketExTransferPlayer.class); registerPacket(0x0075, PacketExTransferPlayer.class);
registerPacket(0x0076, PacketExDisconnectPlayer.class); registerPacket(0x0076, PacketExDisconnectPlayer.class);
registerPacket(0x0077, PacketExMessagePlayer.class); registerPacket(0x0077, PacketExMessagePlayer.class);
registerPacket(0x0078, PacketExControlPlayer.class);
//registerPacket(0x0070, new PacketOutRunEvent()); //registerPacket(0x0070, new PacketOutRunEvent());
//registerPacket(0x0071, new PacketOutReset()); //registerPacket(0x0071, new PacketOutReset());
@ -138,6 +139,7 @@ public class SubProtocol extends SubDataProtocol {
registerPacket(0x0075, new PacketExTransferPlayer()); registerPacket(0x0075, new PacketExTransferPlayer());
registerPacket(0x0076, new PacketExDisconnectPlayer()); registerPacket(0x0076, new PacketExDisconnectPlayer());
registerPacket(0x0077, new PacketExMessagePlayer()); registerPacket(0x0077, new PacketExMessagePlayer());
registerPacket(0x0078, new PacketExControlPlayer());
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -464,8 +464,11 @@ public final class SubAPI implements BungeeAPI {
* @return Success Status * @return Success Status
*/ */
public boolean removeServer(UUID player, String name) { public boolean removeServer(UUID player, String name) {
Util.nullpo(name, getServer(name)); Util.nullpo(name);
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name)); Server server = getServer(name);
if (server == null) return true;
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, server);
plugin.getPluginManager().callEvent(event); plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
plugin.exServers.remove(name.toLowerCase()); plugin.exServers.remove(name.toLowerCase());
@ -491,8 +494,11 @@ public final class SubAPI implements BungeeAPI {
* @return Success Status * @return Success Status
*/ */
public boolean forceRemoveServer(UUID player, String name) { public boolean forceRemoveServer(UUID player, String name) {
Util.nullpo(name, getServer(name)); Util.nullpo(name);
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name)); Server server = getServer(name);
if (server == null) return true;
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, server);
plugin.getPluginManager().callEvent(event); plugin.getPluginManager().callEvent(event);
plugin.exServers.remove(name.toLowerCase()); plugin.exServers.remove(name.toLowerCase());
return true; return true;

View File

@ -523,8 +523,8 @@ public final class SubCommand extends Command implements TabExecutor {
} }
} else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) { } else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) {
if (args.length > 1) { if (args.length > 1) {
ServerSelection select = selectServers(sender, args, 1, true); ServerSelection select = selectServers(sender, args, 1, false);
if (select.subservers.length > 0) { if (select.servers.length > 0) {
if (select.args.length > 2) { if (select.args.length > 2) {
StringBuilder builder = new StringBuilder(select.args[2]); StringBuilder builder = new StringBuilder(select.args[2]);
for (int i = 3; i < select.args.length; i++) { for (int i = 3; i < select.args.length; i++) {
@ -534,21 +534,29 @@ public final class SubCommand extends Command implements TabExecutor {
int success = 0, running = 0; int success = 0, running = 0;
String command = builder.toString(); String command = builder.toString();
for (SubServer server : select.subservers) { for (Server server : select.servers) {
if (!server.isRunning()) { if (server instanceof SubServer) {
running++; if (!((SubServer) server).isRunning()) {
} else if (server.command(command)) { running++;
success++; } else if (server.command(command)) {
success++;
}
} else {
if (server.getSubData()[0] == null) {
running++;
} else if (server.command(command)) {
success++;
}
} }
} }
if (running > 0) sender.sendMessage("SubServers > " + running + " subserver"+((running == 1)?" was":"s were") + " offline"); if (running > 0) sender.sendMessage("SubServers > " + running + " server"+((running == 1)?" was":"s were") + " unavailable");
if (success > 0) sender.sendMessage("SubServers > Sent command to " + success + " subserver"+((success == 1)?"":"s")); if (success > 0) sender.sendMessage("SubServers > Sent command to " + success + " server"+((success == 1)?"":"s"));
} else { } else {
sender.sendMessage("SubServers > No command was entered"); sender.sendMessage("SubServers > No command was entered");
} }
} }
} else { } else {
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Subservers> <Command> [Args...]"); sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Servers> <Command> [Args...]");
} }
} else if (args[0].equalsIgnoreCase("sudo") || args[0].equalsIgnoreCase("screen")) { } else if (args[0].equalsIgnoreCase("sudo") || args[0].equalsIgnoreCase("screen")) {
if (plugin.canSudo) { if (plugin.canSudo) {
@ -822,7 +830,7 @@ public final class SubCommand extends Command implements TabExecutor {
" Restart Server: /sub restart <Subservers>", " Restart Server: /sub restart <Subservers>",
" Stop Server: /sub stop <Subservers>", " Stop Server: /sub stop <Subservers>",
" Terminate Server: /sub kill <Subservers>", " Terminate Server: /sub kill <Subservers>",
" Command Server: /sub cmd <Subservers> <Command> [Args...]", " Command Server: /sub cmd <Servers> <Command> [Args...]",
" Sudo Server: /sub sudo <Subserver>", " Sudo Server: /sub sudo <Subserver>",
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]", " Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
" Update Server: /sub update <Subservers> [[Template] <Version>]", " Update Server: /sub update <Subservers> [[Template] <Version>]",
@ -1002,7 +1010,8 @@ public final class SubCommand extends Command implements TabExecutor {
args[0].equals("sudo") || args[0].equals("screen") args[0].equals("sudo") || args[0].equals("screen")
))) { ))) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
ServerSelection select = selectServers(null, args, 1, true); boolean mode = !args[0].equals("cmd") && !args[0].equals("command");
ServerSelection select = selectServers(null, args, 1, mode);
if (select.last != null) { if (select.last != null) {
if (last.startsWith("::")) { if (last.startsWith("::")) {
Map<String, Host> hosts = plugin.api.getHosts(); Map<String, Host> hosts = plugin.api.getHosts();
@ -1027,11 +1036,11 @@ public final class SubCommand extends Command implements TabExecutor {
} }
return list; return list;
} else { } else {
Map<String, SubServer> subservers = plugin.api.getSubServers(); Map<String, Server> servers = (mode)? (Map<String, Server>) (Map<String, ?>) plugin.api.getSubServers() : plugin.api.getServers();
if (subservers.size() > 0) { if (servers.size() > 0) {
if (Arrays.binarySearch(select.selection, "*") < 0 && "*".startsWith(last)) list.add("*"); if (Arrays.binarySearch(select.selection, "*") < 0 && "*".startsWith(last)) list.add("*");
if (sender instanceof ProxiedPlayer && Arrays.binarySearch(select.selection, ".") < 0 && ".".startsWith(last)) list.add("."); if (sender instanceof ProxiedPlayer && Arrays.binarySearch(select.selection, ".") < 0 && ".".startsWith(last)) list.add(".");
for (SubServer server : subservers.values()) { for (Server server : servers.values()) {
if (Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length())); if (Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
} }
} }

View File

@ -155,7 +155,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
Logger.get("SubServers").info("Created ./SubServers/Templates/Sponge"); Logger.get("SubServers").info("Created ./SubServers/Templates/Sponge");
} else { } else {
long stamp = Math.round(Math.random() * 100000); long stamp = Math.round(Math.random() * 100000);
Version tv1 = new Version("2.16a+"); Version tv1 = new Version("2.18a+");
Version tv2 = new Version("2.18a+"); Version tv2 = new Version("2.18a+");
if (new File(dir, "Templates/Vanilla/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Vanilla/template.yml"))).get().getVersion("Version", tv2)).compareTo(tv2) != 0) { if (new File(dir, "Templates/Vanilla/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Vanilla/template.yml"))).get().getVersion("Version", tv2)).compareTo(tv2) != 0) {

View File

@ -15,18 +15,22 @@ public class SubSendCommandEvent extends Event implements SubEvent {
private UUID player; private UUID player;
private String server; private String server;
private String command; private String command;
private UUID target;
/** /**
* Server Command Event * Server Command Event
* *
* @param player Player Commanding Server * @param player Player Commanding
* @param server Server being Commanded * @param server Target Server
* @param command Command to Send
* @param target Player that will send
*/ */
public SubSendCommandEvent(UUID player, String server, String command) { public SubSendCommandEvent(UUID player, String server, String command, UUID target) {
Util.nullpo(server, command); Util.nullpo(server, command);
this.player = player; this.player = player;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.target = target;
} }
/** /**
@ -52,6 +56,15 @@ public class SubSendCommandEvent extends Event implements SubEvent {
return command; return command;
} }
/**
* Gets the Player that will be forced to send the Command
*
* @return Target Player or null if Console
*/
public UUID getTarget() {
return target;
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;

View File

@ -11,6 +11,7 @@ import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketInExRunEvent; import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketInExRunEvent;
import net.ME1312.SubServers.Client.Bukkit.SubPlugin; import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
import net.ME1312.SubServers.Client.Common.Network.API.Host; import net.ME1312.SubServers.Client.Common.Network.API.Host;
import net.ME1312.SubServers.Client.Common.Network.API.Server;
import net.ME1312.SubServers.Client.Common.Network.API.SubServer; import net.ME1312.SubServers.Client.Common.Network.API.SubServer;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketCreateServer; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketCreateServer;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketUpdateServer; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketUpdateServer;
@ -286,15 +287,15 @@ public class DefaultUIHandler implements UIHandler, Listener {
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) {
player.closeInventory(); player.closeInventory();
gui.back(); gui.back();
} else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.startsWith(ChatColor.WHITE.toString()) && !item.equals(plugin.api.getLang("SubServers", "Interface.Server-Menu.No-Servers"))) { } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.Server-Menu.No-Servers"))) {
player.closeInventory(); player.closeInventory();
String obj; String obj;
if (event.getCurrentItem().getItemMeta().getLore() != null && event.getCurrentItem().getItemMeta().getLore().size() > 0 && event.getCurrentItem().getItemMeta().getLore().get(0).startsWith(ChatColor.GRAY.toString())) { if (event.getCurrentItem().getItemMeta().getLore() != null && event.getCurrentItem().getItemMeta().getLore().size() > 0 && event.getCurrentItem().getItemMeta().getLore().get((item.startsWith(ChatColor.WHITE.toString()))? 1 : 0).startsWith(ChatColor.GRAY.toString())) {
obj = ChatColor.stripColor(event.getCurrentItem().getItemMeta().getLore().get(0)); obj = ChatColor.stripColor(event.getCurrentItem().getItemMeta().getLore().get(0));
} else { } else {
obj = ChatColor.stripColor(item); obj = ChatColor.stripColor(item);
} }
gui.subserverAdmin(obj); gui.serverAdmin(obj);
} }
} }
} else if (title.startsWith(plugin.api.getLang("SubServers", "Interface.Host-Admin.Title").split("\\$str\\$")[0]) && // Host Admin } else if (title.startsWith(plugin.api.getLang("SubServers", "Interface.Host-Admin.Title").split("\\$str\\$")[0]) && // Host Admin
@ -319,47 +320,47 @@ public class DefaultUIHandler implements UIHandler, Listener {
gui.hostPlugin(1, ((Host) gui.lastVisitedObjects[0]).getName()); gui.hostPlugin(1, ((Host) gui.lastVisitedObjects[0]).getName());
} }
} }
} else if (title.startsWith(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").split("\\$str\\$")[0]) && // SubServer Admin } else if (title.startsWith(plugin.api.getLang("SubServers", "Interface.Server-Admin.Title").split("\\$str\\$")[0]) && // SubServer Admin
(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").split("\\$str\\$").length == 1 || (plugin.api.getLang("SubServers", "Interface.Server-Admin.Title").split("\\$str\\$").length == 1 ||
title.endsWith(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").split("\\$str\\$")[1]))) { title.endsWith(plugin.api.getLang("SubServers", "Interface.Server-Admin.Title").split("\\$str\\$")[1]))) {
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) { if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
String item = event.getCurrentItem().getItemMeta().getDisplayName(); String item = event.getCurrentItem().getItemMeta().getDisplayName();
if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) {
player.closeInventory(); player.closeInventory();
gui.back(); gui.back();
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Server-Admin.Update"))) {
player.closeInventory(); player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.update")) { if (permits((Server) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.update")) {
if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update.Title"), 4 * 20)) if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.Server-Admin.Update.Title"), 4 * 20))
player.sendMessage(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update.Message")); player.sendMessage(plugin.api.getLang("SubServers", "Interface.Server-Admin.Update.Message"));
input.put(player.getUniqueId(), m -> { input.put(player.getUniqueId(), m -> {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response")); gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player.getUniqueId(), ((SubServer) gui.lastVisitedObjects[0]).getName(), ((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player.getUniqueId(), ((Server) gui.lastVisitedObjects[0]).getName(),
null, (m.getString("message").length() == 0 || m.getString("message").equals("/"))?null:new Version((m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message")), data -> { null, (m.getString("message").length() == 0 || m.getString("message").equals("/"))?null:new Version((m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message")), data -> {
gui.reopen(); gui.reopen();
})); }));
}); });
} else gui.reopen(); } else gui.reopen();
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Server-Admin.Start"))) {
player.closeInventory(); player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.start")) { if (permits((Server) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.start")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response")); gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
((SubServer) gui.lastVisitedObjects[0]).start(player.getUniqueId(), response -> { ((SubServer) gui.lastVisitedObjects[0]).start(player.getUniqueId(), response -> {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start.Title")); gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Server-Admin.Start.Title"));
Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 30); Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 30);
}); });
} else gui.reopen(); } else gui.reopen();
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Stop"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Server-Admin.Stop"))) {
player.closeInventory(); player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.stop")) { if (permits((Server) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.stop")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response")); gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
final Value<Boolean> listening = new Container<Boolean>(true); final Value<Boolean> listening = new Container<Boolean>(true);
PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() { PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() {
@Override @Override
public void accept(ObjectMap<String> json) { public void accept(ObjectMap<String> json) {
try { try {
if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) { if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((Server) gui.lastVisitedObjects[0]).getName())) {
PacketInExRunEvent.callback("SubStoppedEvent", this); PacketInExRunEvent.callback("SubStoppedEvent", this);
} else { } else {
Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 5); Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 5);
@ -371,19 +372,19 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (response != 0) { if (response != 0) {
gui.reopen(); gui.reopen();
listening.value(false); listening.value(false);
} else gui.setDownloading(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Stop.Title").replace("$str$", ((SubServer) gui.lastVisitedObjects[0]).getName())); } else gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Server-Admin.Stop.Title").replace("$str$", ((Server) gui.lastVisitedObjects[0]).getName()));
}); });
} else gui.reopen(); } else gui.reopen();
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Terminate"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Server-Admin.Terminate"))) {
player.closeInventory(); player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.terminate")) { if (permits((Server) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.terminate")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response")); gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
final Value<Boolean> listening = new Container<Boolean>(true); final Value<Boolean> listening = new Container<Boolean>(true);
PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() { PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() {
@Override @Override
public void accept(ObjectMap<String> json) { public void accept(ObjectMap<String> json) {
try { try {
if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) { if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((Server) gui.lastVisitedObjects[0]).getName())) {
PacketInExRunEvent.callback("SubStoppedEvent", this); PacketInExRunEvent.callback("SubStoppedEvent", this);
} else { } else {
gui.reopen(); gui.reopen();
@ -395,24 +396,24 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (response != 0) { if (response != 0) {
gui.reopen(); gui.reopen();
listening.value(false); listening.value(false);
} else gui.setDownloading(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Terminate.Title").replace("$str$", ((SubServer) gui.lastVisitedObjects[0]).getName())); } else gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Server-Admin.Terminate.Title").replace("$str$", ((Server) gui.lastVisitedObjects[0]).getName()));
}); });
} else gui.reopen(); } else gui.reopen();
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Server-Admin.Command"))) {
player.closeInventory(); player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.command")) { if (permits((Server) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.command")) {
if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command.Title"), 4 * 20)) if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.Server-Admin.Command.Title"), 4 * 20))
player.sendMessage(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command.Message")); player.sendMessage(plugin.api.getLang("SubServers", "Interface.Server-Admin.Command.Message"));
input.put(player.getUniqueId(), m -> { input.put(player.getUniqueId(), m -> {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response")); gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
((SubServer) gui.lastVisitedObjects[0]).command(player.getUniqueId(), (m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message"), response -> { ((Server) gui.lastVisitedObjects[0]).command(player.getUniqueId(), (m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message"), response -> {
gui.reopen(); gui.reopen();
}); });
}); });
} else gui.reopen(); } else gui.reopen();
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Plugins"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Server-Admin.Plugins"))) {
player.closeInventory(); player.closeInventory();
gui.subserverPlugin(1, ((SubServer) gui.lastVisitedObjects[0]).getName()); gui.serverPlugin(1, ((Server) gui.lastVisitedObjects[0]).getName());
} }
} }
} else if (title.startsWith(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").split("\\$str\\$")[0]) && // SubServer Plugin } else if (title.startsWith(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").split("\\$str\\$")[0]) && // SubServer Plugin
@ -422,24 +423,24 @@ public class DefaultUIHandler implements UIHandler, Listener {
String item = event.getCurrentItem().getItemMeta().getDisplayName(); String item = event.getCurrentItem().getItemMeta().getDisplayName();
if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back-Arrow"))) { if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back-Arrow"))) {
player.closeInventory(); player.closeInventory();
gui.subserverPlugin(gui.lastPage - 1, ((SubServer) gui.lastVisitedObjects[0]).getName()); gui.serverPlugin(gui.lastPage - 1, ((Server) gui.lastVisitedObjects[0]).getName());
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Next-Arrow"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Next-Arrow"))) {
player.closeInventory(); player.closeInventory();
gui.subserverPlugin(gui.lastPage + 1, ((SubServer) gui.lastVisitedObjects[0]).getName()); gui.serverPlugin(gui.lastPage + 1, ((Server) gui.lastVisitedObjects[0]).getName());
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) {
player.closeInventory(); player.closeInventory();
gui.back(); gui.back();
} else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.No-Plugins"))) { } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.No-Plugins"))) {
player.closeInventory(); player.closeInventory();
Value<PluginRenderer<SubServer>> plugin = new Container<PluginRenderer<SubServer>>(null); Value<PluginRenderer<Server>> plugin = new Container<PluginRenderer<Server>>(null);
for (PluginRenderer<SubServer> renderer : DefaultUIRenderer.subserverPlugins.values()) { for (PluginRenderer<Server> renderer : DefaultUIRenderer.serverPlugins.values()) {
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.value(renderer); if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.value(renderer);
} }
if (plugin.value() == null) { if (plugin.value() == null) {
gui.reopen(); gui.reopen();
} else { } else {
gui.setDownloading(ChatColor.stripColor(this.plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", ((SubServer) gui.lastVisitedObjects[0]).getName()))); gui.setDownloading(ChatColor.stripColor(this.plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", ((Server) gui.lastVisitedObjects[0]).getName())));
this.plugin.api.getSubServer(((SubServer) gui.lastVisitedObjects[0]).getName(), subserver -> { this.plugin.api.getSubServer(((Server) gui.lastVisitedObjects[0]).getName(), subserver -> {
if (subserver != null) { if (subserver != null) {
gui.setDownloading(null); gui.setDownloading(null);
plugin.value().open(player, subserver); plugin.value().open(player, subserver);

View File

@ -18,6 +18,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; import java.util.*;
import java.util.function.BiConsumer;
import static net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permits; import static net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permits;
@ -290,7 +291,7 @@ public class DefaultUIRenderer extends UIRenderer {
inv.setItem(15, block); inv.setItem(15, block);
inv.setItem(16, block); inv.setItem(16, block);
if (!host.isAvailable() || !host.isEnabled() || hostPlugins.size() <= 0) { if (hostPlugins.size() <= 0) {
block = div; block = div;
} else { } else {
block = color(11); block = color(11);
@ -595,7 +596,7 @@ public class DefaultUIRenderer extends UIRenderer {
lastVisitedObjects[0] = host; lastVisitedObjects[0] = host;
lastPage = page; lastPage = page;
List<String> renderers = new LinkedList<String>(); List<String> renderers = new LinkedList<String>();
for (String renderer : renderers) { for (String renderer : hostPlugins.keySet()) {
if (hostPlugins.get(renderer).isEnabled(host)) renderers.add(renderer); if (hostPlugins.get(renderer).isEnabled(host)) renderers.add(renderer);
} }
Collections.sort(renderers); Collections.sort(renderers);
@ -881,7 +882,6 @@ public class DefaultUIRenderer extends UIRenderer {
lore.add(ChatColor.GRAY + server.getName()); lore.add(ChatColor.GRAY + server.getName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External")); lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getRemotePlayers().size()))); lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getRemotePlayers().size())));
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Invalid"));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort()); lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
blockMeta.setLore(lore); blockMeta.setLore(lore);
} else if (((SubServer) server).isRunning()) { } else if (((SubServer) server).isRunning()) {
@ -1016,229 +1016,250 @@ public class DefaultUIRenderer extends UIRenderer {
} }
} }
public void subserverAdmin(final String name) { public void serverAdmin(final String name) {
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").replace("$str$", name))); setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Title").replace("$str$", name)));
plugin.api.getSubServer(name, subserver -> { BiConsumer<Server, Host> renderer = (server, host) -> {
windowHistory.add(() -> subserverAdmin(name)); setDownloading(null);
if (subserver == null) { lastVisitedObjects[0] = server;
if (hasHistory()) back(); ItemStack block;
} else subserver.getHost(host -> { ItemMeta blockMeta;
if (host == null) { ItemStack div = color(15);
if (hasHistory()) back(); ItemMeta divMeta = div.getItemMeta();
divMeta.setDisplayName(ChatColor.RESET.toString());
div.setItemMeta(divMeta);
Inventory inv = Bukkit.createInventory(null, 36, plugin.api.getLang("SubServers", "Interface.Server-Admin.Title").replace("$str$", server.getDisplayName()));
SubServer subserver = (host != null)? (SubServer) server : null;
int i = 0;
while (i < inv.getSize()) {
inv.setItem(i, div);
i++;
}
i = 0;
Player player = Bukkit.getPlayer(this.player);
if (host == null || ((SubServer) server).isRunning()) {
if (host == null || !permits(server, player, "subservers.subserver.%.*", "subservers.subserver.%.terminate")) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Terminate")));
if (host != null) blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.terminate." + name.toLowerCase())));
} else { } else {
setDownloading(null); block = color(14);
lastVisitedObjects[0] = subserver; blockMeta = block.getItemMeta();
ItemStack block; blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Server-Admin.Terminate"));
ItemMeta blockMeta; }
ItemStack div = color(15);
ItemMeta divMeta = div.getItemMeta();
divMeta.setDisplayName(ChatColor.RESET.toString());
div.setItemMeta(divMeta);
Inventory inv = Bukkit.createInventory(null, 36, plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").replace("$str$", subserver.getDisplayName())); block.setItemMeta(blockMeta);
inv.setItem(1, block);
inv.setItem(10, block);
int i = 0; if (host == null || !permits(server, player, "subservers.subserver.%.*", "subservers.subserver.%.stop")) {
while (i < inv.getSize()) { block = color(7);
inv.setItem(i, div); blockMeta = block.getItemMeta();
i++; blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Stop")));
} if (host != null) blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + name.toLowerCase())));
i = 0; } else {
block = color(2);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Server-Admin.Stop"));
}
block.setItemMeta(blockMeta);
inv.setItem(2, block);
inv.setItem(3, block);
inv.setItem(11, block);
inv.setItem(12, block);
Player player = Bukkit.getPlayer(this.player); if ((host == null && server.getSubData()[0] == null) || !permits(server, player, "subservers.subserver.%.*", "subservers.subserver.%.command")) {
if (subserver.isRunning()) { block = color(7);
if (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.terminate")) { blockMeta = block.getItemMeta();
block = color(7); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Command")));
blockMeta = block.getItemMeta(); if (host != null) blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + name.toLowerCase())));
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Terminate"))); } else {
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.terminate." + name.toLowerCase()))); block = color(3);
} else { blockMeta = block.getItemMeta();
block = color(14); blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Server-Admin.Command"));
blockMeta = block.getItemMeta(); }
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Terminate")); block.setItemMeta(blockMeta);
} inv.setItem(5, block);
inv.setItem(6, block);
inv.setItem(7, block);
inv.setItem(14, block);
inv.setItem(15, block);
inv.setItem(16, block);
} else {
if (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.start")) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Start")));
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + name.toLowerCase())));
} else if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || !subserver.isEnabled() || subserver.getCurrentIncompatibilities().size() != 0) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Start")));
} else {
block = color(5);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Server-Admin.Start"));
}
block.setItemMeta(blockMeta);
SubCreator.ServerTemplate template;
if (subserver.getTemplate() == null || !(template = host.getCreator().getTemplate(subserver.getTemplate())).isEnabled() || !template.canUpdate()) {
inv.setItem(3, block);
inv.setItem(4, block);
inv.setItem(5, block);
inv.setItem(12, block);
inv.setItem(13, block);
inv.setItem(14, block);
} else {
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.setItemMeta(blockMeta); if (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.update")) {
inv.setItem(1, block); block = color(7);
inv.setItem(10, block);
if (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.stop")) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Stop")));
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + name.toLowerCase())));
} else {
block = color(2);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Stop"));
}
block.setItemMeta(blockMeta);
inv.setItem(2, block);
inv.setItem(3, block);
inv.setItem(11, block);
inv.setItem(12, block);
if (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.command")) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command")));
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + name.toLowerCase())));
} else {
block = color(3);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command"));
}
block.setItemMeta(blockMeta);
inv.setItem(5, block);
inv.setItem(6, block);
inv.setItem(7, block);
inv.setItem(14, block);
inv.setItem(15, block);
inv.setItem(16, block);
} else {
if (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.start")) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start")));
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + name.toLowerCase())));
} else if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || !subserver.isEnabled() || subserver.getCurrentIncompatibilities().size() != 0) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start")));
} else {
block = color(5);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start"));
}
block.setItemMeta(blockMeta);
SubCreator.ServerTemplate template;
if (subserver.getTemplate() == null || !(template = host.getCreator().getTemplate(subserver.getTemplate())).isEnabled() || !template.canUpdate()) {
inv.setItem(3, block);
inv.setItem(4, block);
inv.setItem(5, block);
inv.setItem(12, block);
inv.setItem(13, block);
inv.setItem(14, block);
} else {
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 (!permits(subserver, player, "subservers.subserver.%.*", "subservers.subserver.%.update")) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update")));
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.update." + name.toLowerCase())));
} else if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || subserver.getCurrentIncompatibilities().size() != 0) {
block = color(7);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update")));
} else {
block = color(4);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update"));
}
block.setItemMeta(blockMeta);
inv.setItem(5, block);
inv.setItem(6, block);
inv.setItem(7, block);
inv.setItem(14, block);
inv.setItem(15, block);
inv.setItem(16, block);
}
}
if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || !subserver.isEnabled() || subserverPlugins.size() <= 0) {
block = div;
} else {
block = color(11);
blockMeta = block.getItemMeta(); blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Plugins")); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Update")));
block.setItemMeta(blockMeta); blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.update." + name.toLowerCase())));
} } else if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || subserver.getCurrentIncompatibilities().size() != 0) {
inv.setItem(27, block); block = color(7);
inv.setItem(28, block);
if (subserver.isRunning()) {
int blocktype = (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER)? 11 : 5;
block = color(blocktype);
blockMeta = block.getItemMeta(); blockMeta = block.getItemMeta();
LinkedList<String> lore = new LinkedList<String>(); blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Server-Admin.Update")));
if (!subserver.getName().equals(subserver.getDisplayName())) } else {
lore.add(ChatColor.GRAY + subserver.getName());
if (subserver.getStopAction() != SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() != SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() != SubServer.StopAction.DELETE_SERVER) {
blockMeta.setDisplayName(ChatColor.AQUA + subserver.getDisplayName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
} else blockMeta.setDisplayName(ChatColor.GREEN + subserver.getDisplayName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getRemotePlayers().size())));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
blockMeta.setLore(lore);
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
block = color(4); block = color(4);
blockMeta = block.getItemMeta(); blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.YELLOW + subserver.getDisplayName()); blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Server-Admin.Update"));
LinkedList<String> lore = new LinkedList<String>();
if (!subserver.getName().equals(subserver.getDisplayName()))
lore.add(ChatColor.GRAY + subserver.getName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
blockMeta.setLore(lore);
} else {
block = color(14);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.RED + subserver.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
if (!subserver.getName().equals(subserver.getDisplayName()))
lore.add(ChatColor.GRAY + subserver.getName());
if (subserver.getCurrentIncompatibilities().size() != 0) {
String list = "";
for (String other : subserver.getCurrentIncompatibilities()) {
if (list.length() != 0) list += ", ";
list += other;
}
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list));
}
if (!subserver.isAvailable() || !subserver.isEnabled()) lore.add(plugin.api.getLang("SubServers", (!subserver.isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled"));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
blockMeta.setLore(lore);
} }
block.setItemMeta(blockMeta); block.setItemMeta(blockMeta);
inv.setItem(30, block); inv.setItem(5, block);
inv.setItem(31, block); inv.setItem(6, block);
inv.setItem(32, block); inv.setItem(7, block);
inv.setItem(14, block);
if (hasHistory()) { inv.setItem(15, block);
block = color(14); inv.setItem(16, block);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Generic.Back"));
block.setItemMeta(blockMeta);
inv.setItem(34, block);
inv.setItem(35, block);
}
player.openInventory(inv);
open = true;
} }
}); }
});
if (serverPlugins.size() > 0) {
block = color(11);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Server-Admin.Plugins"));
block.setItemMeta(blockMeta);
} else {
block = div;
}
inv.setItem(27, block);
inv.setItem(28, block);
if (host == null) {
block = color(0);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.WHITE + server.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
if (!server.getName().equals(server.getDisplayName()))
lore.add(ChatColor.GRAY + server.getName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getRemotePlayers().size())));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
blockMeta.setLore(lore);
} else if (subserver.isRunning()) {
int blocktype = (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER)? 11 : 5;
block = color(blocktype);
blockMeta = block.getItemMeta();
LinkedList<String> lore = new LinkedList<String>();
if (!subserver.getName().equals(subserver.getDisplayName()))
lore.add(ChatColor.GRAY + subserver.getName());
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
blockMeta.setDisplayName(ChatColor.AQUA + subserver.getDisplayName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
} else blockMeta.setDisplayName(ChatColor.GREEN + subserver.getDisplayName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getRemotePlayers().size())));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
blockMeta.setLore(lore);
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
block = color(4);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.YELLOW + subserver.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
if (!subserver.getName().equals(subserver.getDisplayName()))
lore.add(ChatColor.GRAY + subserver.getName());
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
blockMeta.setLore(lore);
} else {
block = color(14);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.RED + subserver.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
if (!subserver.getName().equals(subserver.getDisplayName()))
lore.add(ChatColor.GRAY + subserver.getName());
if (subserver.getCurrentIncompatibilities().size() != 0) {
String list = "";
for (String other : subserver.getCurrentIncompatibilities()) {
if (list.length() != 0) list += ", ";
list += other;
}
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list));
}
if (!subserver.isAvailable() || !subserver.isEnabled()) lore.add(plugin.api.getLang("SubServers", (!subserver.isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled"));
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
blockMeta.setLore(lore);
}
block.setItemMeta(blockMeta);
inv.setItem(30, block);
inv.setItem(31, block);
inv.setItem(32, block);
if (hasHistory()) {
block = color(14);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Generic.Back"));
block.setItemMeta(blockMeta);
inv.setItem(34, block);
inv.setItem(35, block);
}
player.openInventory(inv);
open = true;
};
plugin.api.getServer(name, server -> {
windowHistory.add(() -> serverAdmin(name));
if (server == null) {
if (hasHistory()) back();
} else {
if (server instanceof SubServer) {
((SubServer) server).getHost(host -> {
if (host == null) {
if (hasHistory()) back();
} else {
renderer.accept(server, host);
}
});
} else {
renderer.accept(server, null);
}
}
});
} }
public void subserverPlugin(final int page, final String name) { public void serverPlugin(final int page, final String name) {
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", name))); setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", name)));
plugin.api.getSubServer(name, subserver -> { plugin.api.getServer(name, server -> {
windowHistory.add(() -> subserverPlugin(page, name)); windowHistory.add(() -> serverPlugin(page, name));
if (subserver == null) { if (server == null) {
if (hasHistory()) back(); if (hasHistory()) back();
} else { } else {
setDownloading(null); setDownloading(null);
lastVisitedObjects[0] = subserver; lastVisitedObjects[0] = server;
lastPage = page; lastPage = page;
List<String> renderers = new LinkedList<String>(); List<String> renderers = new LinkedList<String>();
for (String renderer : renderers) { for (String renderer : serverPlugins.keySet()) {
if (subserverPlugins.get(renderer).isEnabled(subserver)) renderers.add(renderer); if (serverPlugins.get(renderer).isEnabled(server)) renderers.add(renderer);
} }
Collections.sort(renderers); Collections.sort(renderers);
@ -1255,7 +1276,7 @@ public class DefaultUIRenderer extends UIRenderer {
int count = (renderers.size() == 0)?27:((renderers.size() - min >= max)?36:renderers.size() - min); int count = (renderers.size() == 0)?27:((renderers.size() - min >= max)?36:renderers.size() - min);
int area = (count % 9 == 0) ? count : ((count / 9) + 1) * 9; int area = (count % 9 == 0) ? count : ((count / 9) + 1) * 9;
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", subserver.getDisplayName())); Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", server.getDisplayName()));
block = color(7); block = color(7);
block.setItemMeta(divMeta); block.setItemMeta(divMeta);
while (i < area) { while (i < area) {
@ -1271,7 +1292,7 @@ public class DefaultUIRenderer extends UIRenderer {
if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) { if (renderers.indexOf(renderer) >= min && renderers.indexOf(renderer) <= max) {
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
inv.setItem(i, subserverPlugins.get(renderer).getIcon()); inv.setItem(i, serverPlugins.get(renderer).getIcon());
count--; count--;
if (count < 9 && (i == 8 || i == 17 || i == 26)) { if (count < 9 && (i == 8 || i == 17 || i == 26)) {

View File

@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version; import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.SubPlugin; import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
import net.ME1312.SubServers.Client.Common.Network.API.Host; import net.ME1312.SubServers.Client.Common.Network.API.Host;
import net.ME1312.SubServers.Client.Common.Network.API.Server;
import net.ME1312.SubServers.Client.Common.Network.API.SubServer; import net.ME1312.SubServers.Client.Common.Network.API.SubServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -29,7 +30,7 @@ public abstract class UIRenderer {
private final boolean TAPI_PLUGIN; private final boolean TAPI_PLUGIN;
static final HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>(); static final HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>();
static final HashMap<String, PluginRenderer<SubServer>> subserverPlugins = new HashMap<String, PluginRenderer<SubServer>>(); static final HashMap<String, PluginRenderer<Server>> serverPlugins = new HashMap<String, PluginRenderer<Server>>();
private ContainedPair<String, Integer> tdownload = null; private ContainedPair<String, Integer> tdownload = null;
private final String[] adownload; private final String[] adownload;
private int download = -1; private int download = -1;
@ -360,8 +361,8 @@ public abstract class UIRenderer {
* *
* @return Host Plugins * @return Host Plugins
*/ */
public static Map<String, PluginRenderer> getHostPlugins() { public static Map<String, PluginRenderer<Host>> getHostPlugins() {
return new HashMap<String, PluginRenderer>(hostPlugins); return new HashMap<String, PluginRenderer<Host>>(hostPlugins);
} }
/** /**
@ -375,33 +376,33 @@ public abstract class UIRenderer {
} }
/** /**
* Add SubServer Plugin * Add Server Plugin
* *
* @param handle Handle to bind * @param handle Handle to bind
* @param renderer Renderer * @param renderer Renderer
*/ */
public static void addSubServerPlugin(String handle, PluginRenderer<SubServer> renderer) { public static void addServerPlugin(String handle, PluginRenderer<Server> renderer) {
Util.nullpo(handle, renderer); Util.nullpo(handle, renderer);
subserverPlugins.put(handle, renderer); serverPlugins.put(handle, renderer);
} }
/** /**
* Get SubServer Plugins * Get Server Plugins
* *
* @return SubServer Plugins * @return SubServer Plugins
*/ */
public static Map<String, PluginRenderer> getSubServerPlugins() { public static Map<String, PluginRenderer<Server>> getServerPlugins() {
return new HashMap<String, PluginRenderer>(subserverPlugins); return new HashMap<String, PluginRenderer<Server>>(serverPlugins);
} }
/** /**
* Remove SubServer Plugin * Remove Server Plugin
* *
* @param handle Handle * @param handle Handle
*/ */
public static void removeSubServerPlugin(String handle) { public static void removeServerPlugin(String handle) {
Util.nullpo(handle); Util.nullpo(handle);
subserverPlugins.remove(handle); serverPlugins.remove(handle);
} }
/** /**
@ -448,18 +449,18 @@ public abstract class UIRenderer {
public abstract void serverMenu(int page, String host, String group); public abstract void serverMenu(int page, String host, String group);
/** /**
* Opens SubServer/&lt;name&gt; * Opens Server/&lt;name&gt;
* *
* @param server SubServer Name * @param server SubServer Name
*/ */
public abstract void subserverAdmin(String server); public abstract void serverAdmin(String server);
/** /**
* Opens SubServer/&lt;name&gt;/Plugins * Opens Server/&lt;name&gt;/Plugins
* *
* @param server SubServer Name * @param server SubServer Name
*/ */
public abstract void subserverPlugin(int page, String server); public abstract void serverPlugin(int page, String server);
/** /**
* Options Layout Class * Options Layout Class

View File

@ -107,7 +107,7 @@ public class BungeeChat {
} }
hover.setColor(ChatColor.WHITE); hover.setColor(ChatColor.WHITE);
hoverm.add(hover); hoverm.add(hover);
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + server.getName())); message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Server/ " + server.getName()));
} else { } else {
message.setColor(ChatColor.WHITE); message.setColor(ChatColor.WHITE);
hover.setColor(ChatColor.WHITE); hover.setColor(ChatColor.WHITE);
@ -184,7 +184,7 @@ public class BungeeChat {
hoverm = new LinkedList<TextComponent>(); hoverm = new LinkedList<TextComponent>();
message = new TextComponent(subserver.getDisplayName()); message = new TextComponent(subserver.getDisplayName());
hover = new TextComponent(subserver.getDisplayName() + '\n'); hover = new TextComponent(subserver.getDisplayName() + '\n');
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + subserver)); message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Server/ " + subserver));
if (subserver.isRunning()) { if (subserver.isRunning()) {
message.setColor(ChatColor.GREEN); message.setColor(ChatColor.GREEN);
hover.setColor(ChatColor.GREEN); hover.setColor(ChatColor.GREEN);
@ -241,7 +241,7 @@ public class BungeeChat {
} }
hover.setColor(ChatColor.WHITE); hover.setColor(ChatColor.WHITE);
hoverm.add(hover); hoverm.add(hover);
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + subserver.getName())); message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Server/ " + subserver.getName()));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()]))); message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
if (i != 0) msg.addExtra(div); if (i != 0) msg.addExtra(div);
msg.addExtra(message); msg.addExtra(message);
@ -278,6 +278,7 @@ public class BungeeChat {
} }
hover.setColor(ChatColor.WHITE); hover.setColor(ChatColor.WHITE);
hoverm.add(hover); hoverm.add(hover);
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Server/ " + server.getName()));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()]))); message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
if (i != 0) msg.addExtra(div); if (i != 0) msg.addExtra(div);
msg.addExtra(message); msg.addExtra(message);

View File

@ -0,0 +1,68 @@
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
import net.ME1312.SubData.Client.SubDataSender;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.util.UUID;
/**
* Player Control Packet
*/
public class PacketExControlPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private int response;
private UUID tracker;
/**
* New PacketExControlPlayer (In)
*/
public PacketExControlPlayer() {}
/**
* New PacketExControlPlayer (Out)
*
* @param response Response ID
* @param tracker Tracker ID
*/
public PacketExControlPlayer(int response, UUID tracker) {
this.response = response;
this.tracker = tracker;
}
@Override
public ObjectMap<Integer> send(SubDataSender client) {
ObjectMap<Integer> data = new ObjectMap<Integer>();
if (tracker != null) data.set(0x0000, tracker);
data.set(0x0001, response);
return data;
}
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
try {
String command = data.getString(0x0001);
UUID target = (data.contains(0x0002)?data.getUUID(0x0002):null);
CommandSender sender = Bukkit.getConsoleSender();
if (target != null && (sender = Bukkit.getPlayer(target)) == null) {
client.sendPacket(new PacketExControlPlayer(6, tracker));
} else {
Bukkit.getServer().dispatchCommand(sender, command);
client.sendPacket(new PacketExControlPlayer(0, tracker));
}
} catch (Throwable e) {
client.sendPacket(new PacketExControlPlayer(2, tracker));
e.printStackTrace();
}
}
@Override
public int version() {
return 0x0001;
}
}

View File

@ -77,7 +77,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@Override @Override
public void accept(ObjectMap<String> data) { public void accept(ObjectMap<String> data) {
if (plugin.isEnabled()) { if (plugin.isEnabled()) {
Bukkit.getPluginManager().callEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"))); Bukkit.getPluginManager().callEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"), (data.contains("target"))?data.getUUID("target"):null));
callback("SubSendCommandEvent", this); callback("SubSendCommandEvent", this);
} }
} }

View File

@ -36,7 +36,7 @@ public class SubProtocol extends SubDataProtocol {
SubPlugin plugin = SubAPI.getInstance().getInternals(); SubPlugin plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2"); setName("SubServers 2");
addVersion(new Version("2.16a+")); addVersion(new Version("2.18a+"));
// 00-0F: Object Link Packets // 00-0F: Object Link Packets
@ -100,10 +100,12 @@ public class SubProtocol extends SubDataProtocol {
//registerPacket(0x0070, PacketInExRunEvent.class); //registerPacket(0x0070, PacketInExRunEvent.class);
//registerPacket(0x0071, PacketInExReset.class); //registerPacket(0x0071, PacketInExReset.class);
//registerPacket(0x0072, PacketInExReload.class); //registerPacket(0x0072, PacketInExReload.class);
registerPacket(0x0078, PacketExControlPlayer.class);
registerPacket(0x0070, new PacketInExRunEvent(plugin)); registerPacket(0x0070, new PacketInExRunEvent(plugin));
registerPacket(0x0071, new PacketInExReset()); registerPacket(0x0071, new PacketInExReset());
registerPacket(0x0072, new PacketInExReload(plugin)); registerPacket(0x0072, new PacketInExReload(plugin));
registerPacket(0x0078, new PacketExControlPlayer());
} }
public static SubProtocol get() { public static SubProtocol get() {

View File

@ -588,8 +588,8 @@ public final class SubCommand extends Command {
} }
} else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) { } else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) {
if (args.length > 1) { if (args.length > 1) {
selectServers(sender, args, 1, true, new String[]{"subservers.subserver.%.*", "subservers.subserver.%.command"}, select -> { selectServers(sender, args, 1, false, new String[]{"subservers.subserver.%.*", "subservers.subserver.%.command"}, select -> {
if (select.subservers.length > 0) { if (select.servers.length > 0) {
if (select.args.length > 2) { if (select.args.length > 2) {
StringBuilder builder = new StringBuilder(select.args[2]); StringBuilder builder = new StringBuilder(select.args[2]);
for (int i = 3; i < select.args.length; i++) { for (int i = 3; i < select.args.length; i++) {
@ -603,7 +603,7 @@ public final class SubCommand extends Command {
if (running.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString())); if (running.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString()));
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString())); if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString()));
}); });
for (SubServer server : select.subservers) { for (Server server : select.servers) {
merge.reserve(); merge.reserve();
server.command((sender instanceof Player)?((Player) sender).getUniqueId():null, builder.toString(), response -> { server.command((sender instanceof Player)?((Player) sender).getUniqueId():null, builder.toString(), response -> {
switch (response) { switch (response) {
@ -627,7 +627,7 @@ public final class SubCommand extends Command {
} }
}); });
} else { } else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers> <Command> [Args...]")); sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Servers> <Command> [Args...]"));
} }
} else if (args[0].equalsIgnoreCase("create")) { } else if (args[0].equalsIgnoreCase("create")) {
if (args.length > 3) { if (args.length > 3) {
@ -808,12 +808,14 @@ public final class SubCommand extends Command {
else if (args.length > 2) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), null, null); else if (args.length > 2) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), null, null);
else plugin.gui.getRenderer((Player) sender).serverMenu(1, null, null); else plugin.gui.getRenderer((Player) sender).serverMenu(1, null, null);
break; break;
case "server/":
case "subserver/": case "subserver/":
plugin.gui.getRenderer((Player) sender).subserverAdmin(args[2]); plugin.gui.getRenderer((Player) sender).serverAdmin(args[2]);
break; break;
case "server/plugin":
case "subserver/plugin": case "subserver/plugin":
if (args.length > 3) plugin.gui.getRenderer((Player) sender).subserverPlugin(Integer.parseInt(args[3]), args[2]); if (args.length > 3) plugin.gui.getRenderer((Player) sender).serverPlugin(Integer.parseInt(args[3]), args[2]);
else plugin.gui.getRenderer((Player) sender).subserverPlugin(1, args[2]); else plugin.gui.getRenderer((Player) sender).serverPlugin(1, args[2]);
break; break;
} }
} catch (Throwable e) { /* } catch (Throwable e) { /*
@ -1124,7 +1126,7 @@ public final class SubCommand extends Command {
plugin.api.getLang("SubServers", "Command.Help.SubServer.Restart").replace("$str$", label.toLowerCase() + " restart <Subservers>"), plugin.api.getLang("SubServers", "Command.Help.SubServer.Restart").replace("$str$", label.toLowerCase() + " restart <Subservers>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Stop").replace("$str$", label.toLowerCase() + " stop <Subservers>"), plugin.api.getLang("SubServers", "Command.Help.SubServer.Stop").replace("$str$", label.toLowerCase() + " stop <Subservers>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Terminate").replace("$str$", label.toLowerCase() + " kill <Subservers>"), plugin.api.getLang("SubServers", "Command.Help.SubServer.Terminate").replace("$str$", label.toLowerCase() + " kill <Subservers>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Command").replace("$str$", label.toLowerCase() + " cmd <Subservers> <Command> [Args...]"), plugin.api.getLang("SubServers", "Command.Help.SubServer.Command").replace("$str$", label.toLowerCase() + " cmd <Servers> <Command> [Args...]"),
plugin.api.getLang("SubServers", "Command.Help.Host.Create").replace("$str$", label.toLowerCase() + " create <Name> <Host> <Template> [Version] [Port]"), plugin.api.getLang("SubServers", "Command.Help.Host.Create").replace("$str$", label.toLowerCase() + " create <Name> <Host> <Template> [Version] [Port]"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Update").replace("$str$", label.toLowerCase() + " update <Subservers> [[Template] <Version>]"), plugin.api.getLang("SubServers", "Command.Help.SubServer.Update").replace("$str$", label.toLowerCase() + " update <Subservers> [[Template] <Version>]"),
}; };

View File

@ -18,7 +18,7 @@
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId> <artifactId>GalaxiUtil</artifactId>
<version>21w47d</version> <version>21w49a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -9,6 +9,7 @@ import net.ME1312.SubData.Client.DataSender;
import net.ME1312.SubData.Client.Library.ForwardedDataSender; import net.ME1312.SubData.Client.Library.ForwardedDataSender;
import net.ME1312.SubData.Client.SubDataClient; import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Common.ClientAPI; import net.ME1312.SubServers.Client.Common.ClientAPI;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketCommandServer;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadPlayerInfo;
import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadServerInfo; import net.ME1312.SubServers.Client.Common.Network.Packet.PacketDownloadServerInfo;
@ -16,6 +17,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.IntConsumer;
/** /**
* Simplified Server Data Class * Simplified Server Data Class
@ -119,6 +121,79 @@ public class Server {
return new LinkedList<String>(raw.getStringList("group")); return new LinkedList<String>(raw.getStringList("group"));
} }
/**
* Commands the Server
*
* @param player Player who's Commanding
* @param target Player who will Send
* @param command Commmand to Send
* @param response Response Code
*/
public void command(UUID player, UUID target, String command, IntConsumer response) {
Util.nullpo(command, response);
StackTraceElement[] origin = new Exception().getStackTrace();
client().sendPacket(new PacketCommandServer(player, target, getName(), command, data -> {
try {
response.accept(data.getInt(0x0001));
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Commands the Server
*
* @param player Player who's Commanding
* @param command Commmand to Send
* @param response Response Code
*/
public void command(UUID player, String command, IntConsumer response) {
command(player, null, command, response);
}
/**
* Commands the Server
*
* @param command Commmand to Send
* @param response Response Code
*/
public void command(String command, IntConsumer response) {
command(null, command, response);
}
/**
* Commands the Server
*
* @param player Player who's Commanding
* @param target Player who's Commanding
* @param command Command to Send
*/
public void command(UUID player, UUID target, String command) {
command(player, target, command, i -> {});
}
/**
* Commands the Server
*
* @param player Player who's Commanding
* @param command Command to Send
*/
public void command(UUID player, String command) {
command(player, command, i -> {});
}
/**
* Commands the Server
*
* @param command Command to Send
*/
public void command(String command) {
command(command, i -> {});
}
/** /**
* Get players on this server across all known proxies * Get players on this server across all known proxies
* *

View File

@ -218,56 +218,6 @@ public class SubServer extends Server {
terminate(i -> {}); terminate(i -> {});
} }
/**
* Commands the Server
*
* @param player Player who Commanded
* @param command Commmand to Send
* @param response Response Code
*/
public void command(UUID player, String command, IntConsumer response) {
Util.nullpo(command, response);
StackTraceElement[] origin = new Exception().getStackTrace();
client().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
try {
response.accept(data.getInt(0x0001));
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
}));
}
/**
* Commands the Server
*
* @param command Commmand to Send
* @param response Response Code
*/
public void command(String command, IntConsumer response) {
command(null, command, response);
}
/**
* Commands the Server
*
* @param player Player who Commanded
* @param command Command to Send
*/
public void command(UUID player, String command) {
command(player, command, i -> {});
}
/**
* Commands the Server
*
* @param command Command to Send
*/
public void command(String command) {
command(command, i -> {});
}
/** /**
* Edits the Server * Edits the Server
* *

View File

@ -18,6 +18,7 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
private UUID player; private UUID player;
private String server; private String server;
private String command; private String command;
private UUID target;
private UUID tracker; private UUID tracker;
/** /**
@ -29,14 +30,16 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
* New PacketCommandServer (Out) * New PacketCommandServer (Out)
* *
* @param player Player Sending * @param player Player Sending
* @param target Target Player
* @param server Server to send to * @param server Server to send to
* @param command Command to send * @param command Command to send
* @param callback Callbacks * @param callback Callbacks
*/ */
@SafeVarargs @SafeVarargs
public PacketCommandServer(UUID player, String server, String command, Consumer<ObjectMap<Integer>>... callback) { public PacketCommandServer(UUID player, UUID target, String server, String command, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(server, command, callback); Util.nullpo(server, command, callback);
this.player = player; this.player = player;
this.target = target;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID); this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -49,7 +52,8 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
data.set(0x0000, tracker); data.set(0x0000, tracker);
data.set(0x0001, server); data.set(0x0001, server);
data.set(0x0002, command); data.set(0x0002, command);
if (player != null) data.set(0x0003, player.toString()); if (player != null) data.set(0x0003, player);
if (target != null) data.set(0x0004, target);
return data; return data;
} }

View File

@ -51,7 +51,7 @@ public class PacketDeleteServer implements PacketObjectIn<Integer>, PacketObject
data.set(0x0001, server); data.set(0x0001, server);
data.set(0x0002, recycle); data.set(0x0002, recycle);
data.set(0x0003, force); data.set(0x0003, force);
if (player != null) data.set(0x0004, player.toString()); if (player != null) data.set(0x0004, player);
return data; return data;
} }

View File

@ -53,7 +53,7 @@ public class PacketEditServer implements PacketObjectIn<Integer>, PacketObjectOu
data.set(0x0001, server); data.set(0x0001, server);
data.set(0x0002, edit); data.set(0x0002, edit);
data.set(0x0003, perma); data.set(0x0003, perma);
if (player != null) data.set(0x0004, player.toString()); if (player != null) data.set(0x0004, player);
return data; return data;
} }

View File

@ -48,7 +48,7 @@ public class PacketRemoveServer implements PacketObjectIn<Integer>, PacketObject
data.set(0x0000, tracker); data.set(0x0000, tracker);
data.set(0x0001, server); data.set(0x0001, server);
data.set(0x0002, force); data.set(0x0002, force);
if (player != null) data.set(0x0003, player.toString()); if (player != null) data.set(0x0003, player);
return data; return data;
} }

View File

@ -45,7 +45,7 @@ public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjec
ObjectMap<Integer> data = new ObjectMap<Integer>(); ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker); data.set(0x0000, tracker);
data.set(0x0001, server); data.set(0x0001, server);
if (player != null) data.set(0x0002, player.toString()); if (player != null) data.set(0x0002, player);
return data; return data;
} }

View File

@ -45,7 +45,7 @@ public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectO
ObjectMap<Integer> data = new ObjectMap<Integer>(); ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker); data.set(0x0000, tracker);
data.set(0x0001, server); data.set(0x0001, server);
if (player != null) data.set(0x0002, player.toString()); if (player != null) data.set(0x0002, player);
return data; return data;
} }

View File

@ -49,7 +49,7 @@ public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOu
data.set(0x0000, id); data.set(0x0000, id);
data.set(0x0001, server); data.set(0x0001, server);
data.set(0x0002, force); data.set(0x0002, force);
if (player != null) data.set(0x0003, player.toString()); if (player != null) data.set(0x0003, player);
return data; return data;
} }

View File

@ -127,7 +127,7 @@
<links> <links>
<link>https://dev.me1312.net/jenkins/job/GalaxiEngine/javadoc/GalaxiUtil/</link> <link>https://dev.me1312.net/jenkins/job/GalaxiEngine/javadoc/GalaxiUtil/</link>
<link>https://dev.me1312.net/jenkins/job/SubData/javadoc/Client/</link> <link>https://dev.me1312.net/jenkins/job/SubData/javadoc/Client/</link>
<link>https://jd.spongepowered.org/</link> <link>https://jd.spongepowered.org/spongeapi/7.3.0/</link>
</links> </links>
<includeDependencySources>true</includeDependencySources> <includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes> <dependencySourceIncludes>

View File

@ -15,18 +15,22 @@ public class SubSendCommandEvent extends AbstractEvent implements SubEvent {
private UUID player; private UUID player;
private String server; private String server;
private String command; private String command;
private UUID target;
/** /**
* Server Command Event * Server Command Event
* *
* @param player Player Commanding Server * @param player Player Commanding
* @param server Server being Commanded * @param server Target Server
* @param command Command to Send
* @param target Player that will send
*/ */
public SubSendCommandEvent(UUID player, String server, String command) { public SubSendCommandEvent(UUID player, String server, String command, UUID target) {
Util.nullpo(server, command); Util.nullpo(server, command);
this.player = player; this.player = player;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.target = target;
} }
/** /**
@ -52,6 +56,15 @@ public class SubSendCommandEvent extends AbstractEvent implements SubEvent {
return command; return command;
} }
/**
* Gets the Player that will be forced to send the Command
*
* @return Target Player or null if Console
*/
public UUID getTarget() {
return target;
}
/** /**
* Gets the cause of this Event * Gets the cause of this Event
* *

View File

@ -7,6 +7,7 @@ import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version; import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Common.Network.API.Host; import net.ME1312.SubServers.Client.Common.Network.API.Host;
import net.ME1312.SubServers.Client.Common.Network.API.Server;
import net.ME1312.SubServers.Client.Common.Network.API.SubServer; import net.ME1312.SubServers.Client.Common.Network.API.SubServer;
import net.ME1312.SubServers.Client.Sponge.Library.Compatibility.ChatColor; import net.ME1312.SubServers.Client.Sponge.Library.Compatibility.ChatColor;
import net.ME1312.SubServers.Client.Sponge.SubPlugin; import net.ME1312.SubServers.Client.Sponge.SubPlugin;
@ -25,7 +26,7 @@ import java.util.concurrent.TimeUnit;
*/ */
public abstract class UIRenderer { public abstract class UIRenderer {
static HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>(); static HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>();
static HashMap<String, PluginRenderer<SubServer>> subserverPlugins = new HashMap<String, PluginRenderer<SubServer>>(); static HashMap<String, PluginRenderer<Server>> serverPlugins = new HashMap<String, PluginRenderer<Server>>();
private Pair<String, Integer> tdownload = null; private Pair<String, Integer> tdownload = null;
private UUID download = null; private UUID download = null;
private final UUID player; private final UUID player;
@ -252,33 +253,33 @@ public abstract class UIRenderer {
} }
/** /**
* Add SubServer Plugin * Add Server Plugin
* *
* @param handle Handle to bind * @param handle Handle to bind
* @param renderer Renderer * @param renderer Renderer
*/ */
public static void addSubServerPlugin(String handle, PluginRenderer<SubServer> renderer) { public static void addServerPlugin(String handle, PluginRenderer<Server> renderer) {
Util.nullpo(handle, renderer); Util.nullpo(handle, renderer);
subserverPlugins.put(handle, renderer); serverPlugins.put(handle, renderer);
} }
/** /**
* Get SubServer Plugins * Get Server Plugins
* *
* @return SubServer Plugins * @return SubServer Plugins
*/ */
public static Map<String, PluginRenderer<SubServer>> getSubServerPlugins() { public static Map<String, PluginRenderer<Server>> getServerPlugins() {
return new HashMap<String, PluginRenderer<SubServer>>(subserverPlugins); return new HashMap<String, PluginRenderer<Server>>(serverPlugins);
} }
/** /**
* Remove SubServer Plugin * Remove Server Plugin
* *
* @param handle Handle * @param handle Handle
*/ */
public static void removeSubServerPlugin(String handle) { public static void removeServerPlugin(String handle) {
Util.nullpo(handle); Util.nullpo(handle);
subserverPlugins.remove(handle); serverPlugins.remove(handle);
} }
/** /**
@ -325,18 +326,18 @@ public abstract class UIRenderer {
public abstract void serverMenu(int page, String host, String group); public abstract void serverMenu(int page, String host, String group);
/** /**
* Opens SubServer/&lt;name&gt; * Opens Server/&lt;name&gt;
* *
* @param server SubServer Name * @param server SubServer Name
*/ */
public abstract void subserverAdmin(String server); public abstract void serverAdmin(String server);
/** /**
* Opens SubServer/&lt;name&gt;/Plugins * Opens Server/&lt;name&gt;/Plugins
* *
* @param server SubServer Name * @param server SubServer Name
*/ */
public abstract void subserverPlugin(int page, String server); public abstract void serverPlugin(int page, String server);
/** /**
* Options Layout Class * Options Layout Class

View File

@ -0,0 +1,69 @@
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
import net.ME1312.SubData.Client.SubDataSender;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;
import java.util.UUID;
/**
* Player Control Packet
*/
public class PacketExControlPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private int response;
private UUID tracker;
/**
* New PacketExControlPlayer (In)
*/
public PacketExControlPlayer() {}
/**
* New PacketExControlPlayer (Out)
*
* @param response Response ID
* @param tracker Tracker ID
*/
public PacketExControlPlayer(int response, UUID tracker) {
this.response = response;
this.tracker = tracker;
}
@Override
public ObjectMap<Integer> send(SubDataSender client) {
ObjectMap<Integer> data = new ObjectMap<Integer>();
if (tracker != null) data.set(0x0000, tracker);
data.set(0x0001, response);
return data;
}
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
try {
String command = data.getString(0x0001);
UUID target = (data.contains(0x0002)?data.getUUID(0x0002):null);
CommandSource sender = Sponge.getServer().getConsole();
if (target != null && (sender = Sponge.getServer().getPlayer(target).orElse(null)) == null) {
client.sendPacket(new PacketExControlPlayer(6, tracker));
} else {
Sponge.getCommandManager().process(sender, command);
client.sendPacket(new PacketExControlPlayer(0, tracker));
}
} catch (Throwable e) {
client.sendPacket(new PacketExControlPlayer(2, tracker));
e.printStackTrace();
}
}
@Override
public int version() {
return 0x0001;
}
}

View File

@ -66,7 +66,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() { callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() {
@Override @Override
public void accept(ObjectMap<String> data) { public void accept(ObjectMap<String> data) {
Sponge.getEventManager().post(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"))); Sponge.getEventManager().post(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"), (data.contains("target"))?data.getUUID("target"):null));
callback("SubSendCommandEvent", this); callback("SubSendCommandEvent", this);
} }
}); });

View File

@ -39,7 +39,7 @@ public class SubProtocol extends SubDataProtocol {
SubPlugin plugin = SubAPI.getInstance().getInternals(); SubPlugin plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2"); setName("SubServers 2");
addVersion(new Version("2.16a+")); addVersion(new Version("2.18a+"));
// 00-0F: Object Link Packets // 00-0F: Object Link Packets
@ -103,10 +103,12 @@ public class SubProtocol extends SubDataProtocol {
//registerPacket(0x0070, PacketInExRunEvent.class); //registerPacket(0x0070, PacketInExRunEvent.class);
//registerPacket(0x0071, PacketInExReset.class); //registerPacket(0x0071, PacketInExReset.class);
//registerPacket(0x0072, PacketInExReload.class); //registerPacket(0x0072, PacketInExReload.class);
registerPacket(0x0078, PacketExControlPlayer.class);
registerPacket(0x0070, new PacketInExRunEvent(plugin)); registerPacket(0x0070, new PacketInExRunEvent(plugin));
registerPacket(0x0071, new PacketInExReset()); registerPacket(0x0071, new PacketInExReset());
registerPacket(0x0072, new PacketInExReload(plugin)); registerPacket(0x0072, new PacketInExReload(plugin));
registerPacket(0x0078, new PacketExControlPlayer());
} }
public static SubProtocol get() { public static SubProtocol get() {

View File

@ -255,7 +255,7 @@ public final class SubCommand implements CommandExecutor {
Text.Builder message = Text.builder(server.getDisplayName()); Text.Builder message = Text.builder(server.getDisplayName());
Text.Builder hover = Text.builder(server.getDisplayName() + '\n'); Text.Builder hover = Text.builder(server.getDisplayName() + '\n');
if (server instanceof SubServer) { if (server instanceof SubServer) {
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + server.getName())); message.onClick(TextActions.runCommand("/subservers open Server/ " + server.getName()));
if (((SubServer) server).isRunning()) { if (((SubServer) server).isRunning()) {
message.color(TextColors.GREEN); message.color(TextColors.GREEN);
hover.color(TextColors.GREEN); hover.color(TextColors.GREEN);
@ -302,7 +302,7 @@ public final class SubCommand implements CommandExecutor {
} else { } else {
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build()); hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
} }
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + server.getName())); message.onClick(TextActions.runCommand("/subservers open Server/ " + server.getName()));
} else { } else {
message.color(TextColors.WHITE); message.color(TextColors.WHITE);
hover.color(TextColors.WHITE); hover.color(TextColors.WHITE);
@ -404,7 +404,7 @@ public final class SubCommand implements CommandExecutor {
} else { } else {
hover.append(Text.builder("\n" + subserver.getAddress().getPort()).color(TextColors.WHITE).build()); hover.append(Text.builder("\n" + subserver.getAddress().getPort()).color(TextColors.WHITE).build());
} }
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + subserver.getName())); message.onClick(TextActions.runCommand("/subservers open Server/ " + subserver.getName()));
message.onHover(TextActions.showText(hover.build())); message.onHover(TextActions.showText(hover.build()));
if (i != 0) msg.append(div); if (i != 0) msg.append(div);
msg.append(message.build()); msg.append(message.build());
@ -434,6 +434,7 @@ public final class SubCommand implements CommandExecutor {
} else { } else {
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build()); hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
} }
message.onClick(TextActions.runCommand("/subservers open Server/ " + server.getName()));
message.onHover(TextActions.showText(hover.build())); message.onHover(TextActions.showText(hover.build()));
if (i != 0) msg.append(div); if (i != 0) msg.append(div);
msg.append(message.build()); msg.append(message.build());
@ -955,8 +956,8 @@ public final class SubCommand implements CommandExecutor {
Optional<String[]> s = args.getOne(Text.of("Subservers")); Optional<String[]> s = args.getOne(Text.of("Subservers"));
Optional<String> command = args.getOne(Text.of("Command")); Optional<String> command = args.getOne(Text.of("Command"));
if (s.isPresent()) { if (s.isPresent()) {
selectServers(sender, s.get(), true, new String[]{"subservers.subserver.%.*", "subservers.subserver.%.command"}, select -> { selectServers(sender, s.get(), false, new String[]{"subservers.subserver.%.*", "subservers.subserver.%.command"}, select -> {
if (select.subservers.length > 0) { if (select.servers.length > 0) {
if (command.isPresent()) { if (command.isPresent()) {
Container<Integer> success = new Container<Integer>(0); Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0); Container<Integer> running = new Container<Integer>(0);
@ -964,7 +965,7 @@ public final class SubCommand implements CommandExecutor {
if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString()))); if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString())));
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString()))); if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString())));
}); });
for (SubServer server : select.subservers) { for (Server server : select.servers) {
merge.reserve(); merge.reserve();
server.command((sender instanceof Player)?((Player) sender).getUniqueId():null, command.get(), response -> { server.command((sender instanceof Player)?((Player) sender).getUniqueId():null, command.get(), response -> {
switch (response) { switch (response) {
@ -989,7 +990,7 @@ public final class SubCommand implements CommandExecutor {
}); });
return CommandResult.builder().successCount(1).build(); return CommandResult.builder().successCount(1).build();
} else { } else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub command <Subservers> <Command> [Args...]"))); sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub command <Servers> <Command> [Args...]")));
return CommandResult.builder().successCount(0).build(); return CommandResult.builder().successCount(0).build();
} }
} else { } else {
@ -1308,12 +1309,14 @@ public final class SubCommand implements CommandExecutor {
else if (menuopts.length > 0) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(menuopts[0]), null, null); else if (menuopts.length > 0) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(menuopts[0]), null, null);
else plugin.gui.getRenderer((Player) sender).serverMenu(1, null, null); else plugin.gui.getRenderer((Player) sender).serverMenu(1, null, null);
break; break;
case "server/":
case "subserver/": case "subserver/":
plugin.gui.getRenderer((Player) sender).subserverAdmin(menuopts[0]); plugin.gui.getRenderer((Player) sender).serverAdmin(menuopts[0]);
break; break;
case "server/plugin":
case "subserver/plugin": case "subserver/plugin":
if (menuopts.length > 1) plugin.gui.getRenderer((Player) sender).subserverPlugin(Integer.parseInt(menuopts[1]), menuopts[0]); if (menuopts.length > 1) plugin.gui.getRenderer((Player) sender).serverPlugin(Integer.parseInt(menuopts[1]), menuopts[0]);
else plugin.gui.getRenderer((Player) sender).subserverPlugin(1, menuopts[0]); else plugin.gui.getRenderer((Player) sender).serverPlugin(1, menuopts[0]);
break; break;
} }
return CommandResult.builder().successCount(1).build(); return CommandResult.builder().successCount(1).build();
@ -1548,7 +1551,7 @@ public final class SubCommand implements CommandExecutor {
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Restart").replace("$str$", "/sub restart <Subservers>")), ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Restart").replace("$str$", "/sub restart <Subservers>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Stop").replace("$str$", "/sub stop <Subservers>")), ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Stop").replace("$str$", "/sub stop <Subservers>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <Subservers>")), ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <Subservers>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <Subservers> <Command> [Args...]")), ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <Servers> <Command> [Args...]")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> [Version] [Port]")), ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> [Version] [Port]")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Update").replace("$str$", "/sub update <Subservers> [[Template] <Version>]")), ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Update").replace("$str$", "/sub update <Subservers> [[Template] <Version>]")),
}; };

View File

@ -1,4 +1,4 @@
Version: '2.16a+' Version: '2.18a+'
Template: Template:
Enabled: true Enabled: true
Icon: 'lava_bucket' Icon: 'lava_bucket'

View File

@ -1,4 +1,4 @@
Version: '2.16a+' Version: '2.18a+'
Template: Template:
Enabled: true Enabled: true
Icon: 'sponge' Icon: 'sponge'

View File

@ -30,13 +30,13 @@
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId> <artifactId>GalaxiEngine</artifactId>
<version>21w47d</version> <version>21w49a</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUI</artifactId> <artifactId>GalaxiUI</artifactId>
<version>21w47d</version> <version>21w49a</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -12,6 +12,7 @@ public class SubSendCommandEvent extends Event {
private UUID player; private UUID player;
private String server; private String server;
private String command; private String command;
private UUID target;
/** /**
* Server Command Event * Server Command Event
@ -19,11 +20,12 @@ public class SubSendCommandEvent extends Event {
* @param player Player Commanding Server * @param player Player Commanding Server
* @param server Server being Commanded * @param server Server being Commanded
*/ */
public SubSendCommandEvent(UUID player, String server, String command) { public SubSendCommandEvent(UUID player, String server, String command, UUID target) {
Util.nullpo(server, command); Util.nullpo(server, command);
this.player = player; this.player = player;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.target = target;
} }
/** /**
@ -48,4 +50,13 @@ public class SubSendCommandEvent extends Event {
public String getCommand() { public String getCommand() {
return command; return command;
} }
/**
* Gets the Player that will be forced to send the Command
*
* @return Target Player or null if Console
*/
public UUID getTarget() {
return target;
}
} }

View File

@ -63,7 +63,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() { callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() {
@Override @Override
public void accept(ObjectMap<String> data) { public void accept(ObjectMap<String> data) {
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"))); GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"), (data.contains("target"))?data.getUUID("target"):null));
callback("SubSendCommandEvent", this); callback("SubSendCommandEvent", this);
} }
}); });

View File

@ -32,7 +32,7 @@ public class SubProtocol extends SubDataProtocol {
ExHost host = SubAPI.getInstance().getInternals(); ExHost host = SubAPI.getInstance().getInternals();
setName("SubServers 2"); setName("SubServers 2");
addVersion(new Version("2.16a+")); addVersion(new Version("2.18a+"));
// 00-0F: Object Link Packets // 00-0F: Object Link Packets

View File

@ -701,8 +701,8 @@ public class SubCommand {
public void command(CommandSender sender, String handle, String[] args) { public void command(CommandSender sender, String handle, String[] args) {
if (canRun()) { if (canRun()) {
if (args.length > 0) { if (args.length > 0) {
selectServers(sender, args, 0, true, select -> { selectServers(sender, args, 0, false, select -> {
if (select.subservers.length > 0) { if (select.servers.length > 0) {
if (select.args.length > 1) { if (select.args.length > 1) {
StringBuilder builder = new StringBuilder(select.args[1]); StringBuilder builder = new StringBuilder(select.args[1]);
for (int i = 2; i < select.args.length; i++) { for (int i = 2; i < select.args.length; i++) {
@ -713,16 +713,16 @@ public class SubCommand {
Container<Integer> success = new Container<Integer>(0); Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0); Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> { AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(running.value + " subserver"+((running.value == 1)?" was":"s were") + " offline"); if (running.value > 0) sender.sendMessage(running.value + " server"+((running.value == 1)?" was":"s were") + " offline");
if (success.value > 0) sender.sendMessage("Sent command to " + success.value + " subserver"+((success.value == 1)?"":"s")); if (success.value > 0) sender.sendMessage("Sent command to " + success.value + " server"+((success.value == 1)?"":"s"));
}); });
for (SubServer server : select.subservers) { for (Server server : select.servers) {
merge.reserve(); merge.reserve();
server.command(builder.toString(), response -> { server.command(builder.toString(), response -> {
switch (response) { switch (response) {
case 3: case 3:
case 4: case 4:
sender.sendMessage("Subserver " + server.getName() + " has disappeared"); sender.sendMessage("Server " + server.getName() + " has disappeared");
break; break;
case 5: case 5:
running.value++; running.value++;
@ -744,8 +744,8 @@ public class SubCommand {
} }
} }
} }
}.autocomplete(defaultCompletor).usage("<Subservers>", "<Command>", "[Args...]").description("Sends a command to the console of one or more subservers").help( }.autocomplete(new ServerCompletion(0, false, ((sender, label, args, select) -> new String[0]))).usage("<Servers>", "<Command>", "[Args...]").description("Sends a command to the console of one or more servers").help(
"Sends a command to the console of one or more subservers on the network.", "Sends a command to the console of one or more servers on the network.",
"", "",
"Examples:", "Examples:",
" /command Server1 version", " /command Server1 version",

View File

@ -14,6 +14,7 @@ public class SubSendCommandEvent extends Event implements SubEvent {
private UUID player; private UUID player;
private String server; private String server;
private String command; private String command;
private UUID target;
/** /**
* Server Command Event * Server Command Event
@ -21,11 +22,12 @@ public class SubSendCommandEvent extends Event implements SubEvent {
* @param player Player Commanding Server * @param player Player Commanding Server
* @param server Server being Commanded * @param server Server being Commanded
*/ */
public SubSendCommandEvent(UUID player, String server, String command) { public SubSendCommandEvent(UUID player, String server, String command, UUID target) {
Util.nullpo(server, command); Util.nullpo(server, command);
this.player = player; this.player = player;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.target = target;
} }
/** /**
@ -50,4 +52,13 @@ public class SubSendCommandEvent extends Event implements SubEvent {
public String getCommand() { public String getCommand() {
return command; return command;
} }
/**
* Gets the Player that will be forced to send the Command
*
* @return Target Player or null if Console
*/
public UUID getTarget() {
return target;
}
} }

View File

@ -65,7 +65,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() { callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() {
@Override @Override
public void accept(ObjectMap<String> data) { public void accept(ObjectMap<String> data) {
ProxyServer.getInstance().getPluginManager().callEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"))); ProxyServer.getInstance().getPluginManager().callEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"), (data.contains("target"))?data.getUUID("target"):null));
callback("SubSendCommandEvent", this); callback("SubSendCommandEvent", this);
} }
}); });

View File

@ -44,7 +44,7 @@ public class SubProtocol extends SubDataProtocol {
ExProxy plugin = SubAPI.getInstance().getInternals(); ExProxy plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2"); setName("SubServers 2");
addVersion(new Version("2.16a+")); addVersion(new Version("2.18a+"));
// 00-0F: Object Link Packets // 00-0F: Object Link Packets

View File

@ -539,8 +539,8 @@ public final class SubCommand extends Command implements TabExecutor {
} }
} else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) { } else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) {
if (args.length > 1) { if (args.length > 1) {
selectServers(sender, args, 1, true, select -> { selectServers(sender, args, 1, false, select -> {
if (select.subservers.length > 0) { if (select.servers.length > 0) {
if (select.args.length > 2) { if (select.args.length > 2) {
StringBuilder builder = new StringBuilder(select.args[2]); StringBuilder builder = new StringBuilder(select.args[2]);
for (int i = 3; i < select.args.length; i++) { for (int i = 3; i < select.args.length; i++) {
@ -551,16 +551,16 @@ public final class SubCommand extends Command implements TabExecutor {
Container<Integer> success = new Container<Integer>(0); Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0); Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> { AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage("SubServers > " + running.value + " subserver"+((running.value == 1)?" was":"s were") + " offline"); if (running.value > 0) sender.sendMessage("SubServers > " + running.value + " server"+((running.value == 1)?" was":"s were") + " offline");
if (success.value > 0) sender.sendMessage("SubServers > Sent command to " + success.value + " subserver"+((success.value == 1)?"":"s")); if (success.value > 0) sender.sendMessage("SubServers > Sent command to " + success.value + " server"+((success.value == 1)?"":"s"));
}); });
for (SubServer server : select.subservers) { for (Server server : select.servers) {
merge.reserve(); merge.reserve();
server.command(builder.toString(), response -> { server.command(builder.toString(), response -> {
switch (response) { switch (response) {
case 3: case 3:
case 4: case 4:
sender.sendMessage("SubServers > Subserver " + server.getName() + " has disappeared"); sender.sendMessage("SubServers > Server " + server.getName() + " has disappeared");
break; break;
case 5: case 5:
running.value++; running.value++;
@ -578,7 +578,7 @@ public final class SubCommand extends Command implements TabExecutor {
} }
}); });
} else { } else {
sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <Subservers> <Command> [Args...]"); sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <Servers> <Command> [Args...]");
} }
} else if (args[0].equalsIgnoreCase("create")) { } else if (args[0].equalsIgnoreCase("create")) {
if (args.length > 3) { if (args.length > 3) {
@ -919,7 +919,7 @@ public final class SubCommand extends Command implements TabExecutor {
" Restart Server: /sub restart <Subservers>", " Restart Server: /sub restart <Subservers>",
" Stop Server: /sub stop <Subservers>", " Stop Server: /sub stop <Subservers>",
" Terminate Server: /sub kill <Subservers>", " Terminate Server: /sub kill <Subservers>",
" Command Server: /sub cmd <Subservers> <Command> [Args...]", " Command Server: /sub cmd <Servers> <Command> [Args...]",
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]", " Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
" Update Server: /sub update <Subservers> [[Template] <Version>]", " Update Server: /sub update <Subservers> [[Template] <Version>]",
" Remove Server: /sub delete <Subservers>", " Remove Server: /sub delete <Subservers>",
@ -1084,7 +1084,8 @@ public final class SubCommand extends Command implements TabExecutor {
args[0].equals("update") || args[0].equals("upgrade") || args[0].equals("update") || args[0].equals("upgrade") ||
args[0].equals("remove") || args[0].equals("del") || args[0].equals("delete")) { args[0].equals("remove") || args[0].equals("del") || args[0].equals("delete")) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
RawServerSelection select = selectRawServers(null, args, 1, true); boolean mode = !args[0].equals("cmd") && !args[0].equals("command");
RawServerSelection select = selectRawServers(null, args, 1, mode);
if (select.last != null) { if (select.last != null) {
if (last.startsWith("::")) { if (last.startsWith("::")) {
Map<String, Host> hosts = hostCache; Map<String, Host> hosts = hostCache;
@ -1109,12 +1110,12 @@ public final class SubCommand extends Command implements TabExecutor {
} }
return list; return list;
} else { } else {
Map<String, ServerImpl> subservers = plugin.servers; Map<String, ServerImpl> servers = plugin.servers;
if (subservers.size() > 0) { if (servers.size() > 0) {
if (Arrays.binarySearch(select.selection, "*") < 0 && "*".startsWith(last)) list.add("*"); if (Arrays.binarySearch(select.selection, "*") < 0 && "*".startsWith(last)) list.add("*");
if (sender instanceof ProxiedPlayer && Arrays.binarySearch(select.selection, ".") < 0 && ".".startsWith(last)) list.add("."); if (sender instanceof ProxiedPlayer && Arrays.binarySearch(select.selection, ".") < 0 && ".".startsWith(last)) list.add(".");
for (ServerImpl server : subservers.values()) { for (ServerImpl server : servers.values()) {
if (server instanceof SubServerImpl && Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length())); if ((!mode || server instanceof SubServerImpl) && Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
} }
} }
return list; return list;

View File

@ -12,6 +12,7 @@ public class SubSendCommandEvent implements SubEvent {
private UUID player; private UUID player;
private String server; private String server;
private String command; private String command;
private UUID target;
/** /**
* Server Command Event * Server Command Event
@ -19,11 +20,12 @@ public class SubSendCommandEvent implements SubEvent {
* @param player Player Commanding Server * @param player Player Commanding Server
* @param server Server being Commanded * @param server Server being Commanded
*/ */
public SubSendCommandEvent(UUID player, String server, String command) { public SubSendCommandEvent(UUID player, String server, String command, UUID target) {
Util.nullpo(server, command); Util.nullpo(server, command);
this.player = player; this.player = player;
this.server = server; this.server = server;
this.command = command; this.command = command;
this.target = target;
} }
/** /**
@ -48,4 +50,13 @@ public class SubSendCommandEvent implements SubEvent {
public String getCommand() { public String getCommand() {
return command; return command;
} }
/**
* Gets the Player that will be forced to send the Command
*
* @return Target Player or null if Console
*/
public UUID getTarget() {
return target;
}
} }

View File

@ -63,7 +63,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() { callback("SubSendCommandEvent", new Consumer<ObjectMap<String>>() {
@Override @Override
public void accept(ObjectMap<String> data) { public void accept(ObjectMap<String> data) {
ExProxy.getInstance().getEventManager().fire(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"))); ExProxy.getInstance().getEventManager().fire(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command"), (data.contains("target"))?data.getUUID("target"):null));
callback("SubSendCommandEvent", this); callback("SubSendCommandEvent", this);
} }
}); });

View File

@ -41,7 +41,7 @@ public class SubProtocol extends SubDataProtocol {
ExProxy plugin = SubAPI.getInstance().getInternals(); ExProxy plugin = SubAPI.getInstance().getInternals();
setName("SubServers 2"); setName("SubServers 2");
addVersion(new Version("2.16a+")); addVersion(new Version("2.18a+"));
// 00-0F: Object Link Packets // 00-0F: Object Link Packets

View File

@ -544,8 +544,8 @@ public final class SubCommand implements SimpleCommand {
} }
} else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) { } else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) {
if (args.length > 1) { if (args.length > 1) {
selectServers(sender, args, 1, true, select -> { selectServers(sender, args, 1, false, select -> {
if (select.subservers.length > 0) { if (select.servers.length > 0) {
if (select.args.length > 2) { if (select.args.length > 2) {
StringBuilder builder = new StringBuilder(select.args[2]); StringBuilder builder = new StringBuilder(select.args[2]);
for (int i = 3; i < select.args.length; i++) { for (int i = 3; i < select.args.length; i++) {
@ -556,16 +556,16 @@ public final class SubCommand implements SimpleCommand {
Container<Integer> success = new Container<Integer>(0); Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0); Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> { AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(Component.text("SubServers > " + running.value + " subserver"+((running.value == 1)?" was":"s were") + " offline")); if (running.value > 0) sender.sendMessage(Component.text("SubServers > " + running.value + " server"+((running.value == 1)?" was":"s were") + " offline"));
if (success.value > 0) sender.sendMessage(Component.text("SubServers > Sent command to " + success.value + " subserver"+((success.value == 1)?"":"s"))); if (success.value > 0) sender.sendMessage(Component.text("SubServers > Sent command to " + success.value + " server"+((success.value == 1)?"":"s")));
}); });
for (SubServer server : select.subservers) { for (Server server : select.servers) {
merge.reserve(); merge.reserve();
server.command(builder.toString(), response -> { server.command(builder.toString(), response -> {
switch (response) { switch (response) {
case 3: case 3:
case 4: case 4:
sender.sendMessage(Component.text("SubServers > Subserver " + server.getName() + " has disappeared")); sender.sendMessage(Component.text("SubServers > Server " + server.getName() + " has disappeared"));
break; break;
case 5: case 5:
running.value++; running.value++;
@ -583,7 +583,7 @@ public final class SubCommand implements SimpleCommand {
} }
}); });
} else { } else {
sender.sendMessage(Component.text("Usage: " + label + " " + args[0].toLowerCase() + " <Subservers> <Command> [Args...]")); sender.sendMessage(Component.text("Usage: " + label + " " + args[0].toLowerCase() + " <Servers> <Command> [Args...]"));
} }
} else if (args[0].equalsIgnoreCase("create")) { } else if (args[0].equalsIgnoreCase("create")) {
if (args.length > 3) { if (args.length > 3) {
@ -924,7 +924,7 @@ public final class SubCommand implements SimpleCommand {
" Restart Server: /sub restart <Subservers>", " Restart Server: /sub restart <Subservers>",
" Stop Server: /sub stop <Subservers>", " Stop Server: /sub stop <Subservers>",
" Terminate Server: /sub kill <Subservers>", " Terminate Server: /sub kill <Subservers>",
" Command Server: /sub cmd <Subservers> <Command> [Args...]", " Command Server: /sub cmd <Servers> <Command> [Args...]",
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]", " Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
" Update Server: /sub update <Subservers> [[Template] <Version>]", " Update Server: /sub update <Subservers> [[Template] <Version>]",
" Remove Server: /sub delete <Subservers>", " Remove Server: /sub delete <Subservers>",
@ -1093,7 +1093,8 @@ public final class SubCommand implements SimpleCommand {
args[0].equals("update") || args[0].equals("upgrade") || args[0].equals("update") || args[0].equals("upgrade") ||
args[0].equals("remove") || args[0].equals("del") || args[0].equals("delete")) { args[0].equals("remove") || args[0].equals("del") || args[0].equals("delete")) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
RawServerSelection select = selectRawServers(null, args, 1, true); boolean mode = !args[0].equals("cmd") && !args[0].equals("command");
RawServerSelection select = selectRawServers(null, args, 1, mode);
if (select.last != null) { if (select.last != null) {
if (last.startsWith("::")) { if (last.startsWith("::")) {
Map<String, Host> hosts = hostCache; Map<String, Host> hosts = hostCache;
@ -1123,7 +1124,7 @@ public final class SubCommand implements SimpleCommand {
if (Arrays.binarySearch(select.selection, "*") < 0 && "*".startsWith(last)) list.add("*"); if (Arrays.binarySearch(select.selection, "*") < 0 && "*".startsWith(last)) list.add("*");
if (sender instanceof Player && Arrays.binarySearch(select.selection, ".") < 0 && ".".startsWith(last)) list.add("."); if (sender instanceof Player && Arrays.binarySearch(select.selection, ".") < 0 && ".".startsWith(last)) list.add(".");
for (ServerData server : subservers.values()) { for (ServerData server : subservers.values()) {
if (server instanceof SubServerData && Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length())); if ((!mode || server instanceof SubServerData) && Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
} }
} }
return list; return list;