mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-01-10 18:07:54 +01:00
Fixes for Multi-Channel SubData
This commit is contained in:
parent
504dc7bac4
commit
2a939117ac
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w19b</version>
|
||||
<version>19w19c</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>19w19c</version>
|
||||
<version>19w19d</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -76,13 +76,13 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(channel) == null)) {
|
||||
if (client != null || channel == 0) {
|
||||
if (client != null || channel == 0) {
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
|
||||
subdata.put(channel, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,15 +50,20 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
boolean update = false;
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(channel) == null)) {
|
||||
if (client != null || channel == 0) {
|
||||
if (client != null || channel == 0) {
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
|
||||
update = true;
|
||||
subdata.put(channel, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
} else {
|
||||
update = true;
|
||||
subdata.remove(channel);
|
||||
}
|
||||
|
||||
if (update) {
|
||||
DataClient[] subdata = getSubData();
|
||||
if (subdata[0] == null && subdata.length <= 1 && !persistent) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
|
||||
|
@ -54,22 +54,25 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
}
|
||||
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
boolean update = false;
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(channel) == null)) {
|
||||
if (client != null || channel == 0) {
|
||||
if (client != null || channel == 0) {
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
|
||||
update = true;
|
||||
subdata.put(channel, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
} else {
|
||||
update = true;
|
||||
subdata.remove(channel);
|
||||
}
|
||||
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", getName());
|
||||
args.set("channel", channel);
|
||||
if (client != null) args.set("address", client.getAddress().toString());
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
}
|
||||
if (update) for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", getName());
|
||||
args.set("channel", channel);
|
||||
if (client != null) args.set("address", client.getAddress().toString());
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage(" -> Available: " + ((host.isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Address: " + ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host instanceof ClientHandler && ((ClientHandler) host).getSubData()[0] != null) sender.sendMessage(" -> Connected: " + ChatColor.GREEN + "yes" + ((((ClientHandler) host).getSubData().length > 1)?ChatColor.AQUA+" +"+(((ClientHandler) host).getSubData().length-1):""));
|
||||
if (host instanceof ClientHandler) sender.sendMessage(" -> Connected: " + ((((ClientHandler) host).getSubData()[0] != null)?ChatColor.GREEN+"yes"+((((ClientHandler) host).getSubData().length > 1)?ChatColor.AQUA+" +"+(((ClientHandler) host).getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
|
@ -48,13 +48,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w19b</version>
|
||||
<version>19w19c</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w19c</version>
|
||||
<version>19w19d</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -55,7 +55,7 @@ public class Host {
|
||||
/**
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||
*/
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
|
@ -28,6 +28,9 @@ public class SubProtocol extends SubDataProtocol {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static SubProtocol get() {
|
||||
if (instance == null) {
|
||||
instance = new SubProtocol();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
@ -35,8 +38,13 @@ public class SubProtocol extends SubDataProtocol {
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open)
|
||||
Bukkit.getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters());
|
||||
if (open) {
|
||||
if (plugin.isEnabled()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters()));
|
||||
} else {
|
||||
Bukkit.getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,8 +57,6 @@ public class SubProtocol extends SubDataProtocol {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
instance = new SubProtocol();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.addVersion(new Version("2.14a+"));
|
||||
|
@ -280,7 +280,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available") + ((host.isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host.getSubData()[0] != null) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ChatColor.GREEN + "yes" + ((host.getSubData().length > 1)?ChatColor.AQUA+" +"+(host.getSubData().length-1):""));
|
||||
if (host.getSubData().length > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((host.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((host.getSubData().length > 1)?ChatColor.AQUA+" +"+(host.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers") + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates") + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
|
@ -47,6 +47,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
public SubPlugin() {
|
||||
super();
|
||||
version = Version.fromString(getDescription().getVersion());
|
||||
subdata.put(0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user