Re-Add fallback functionality

This commit is contained in:
ME1312 2018-10-03 19:18:16 -04:00
parent 261a08d014
commit e5ba821754
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
4 changed files with 48 additions and 18 deletions

View File

@ -1,5 +1,6 @@
Version: '2.13b+' Version: '2.13.1a+'
Lang: Lang:
'Bungee.Feature.Return': '&6Returning to $str$: &r$msg$'
'Bungee.Server.Current': '&6You are currently connected to $str$' 'Bungee.Server.Current': '&6You are currently connected to $str$'
'Bungee.Server.Available': '&6You may connect to the following servers at this time:' 'Bungee.Server.Available': '&6You may connect to the following servers at this time:'
'Bungee.Server.List': '&6$str$' 'Bungee.Server.List': '&6$str$'

View File

@ -20,6 +20,7 @@ import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.BungeeServerInfo; import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -101,7 +102,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
if (!(new UniversalFile(dir, "lang.yml").exists())) { if (!(new UniversalFile(dir, "lang.yml").exists())) {
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath()); Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath());
System.out.println("SubServers > Created ~/SubServers/lang.yml"); System.out.println("SubServers > Created ~/SubServers/lang.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13b+"))) != 0) { } else if ((new Version((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13.1a+"))) != 0) {
Files.move(new UniversalFile(dir, "lang.yml").toPath(), new UniversalFile(dir, "lang.old" + Math.round(Math.random() * 100000) + ".yml").toPath()); Files.move(new UniversalFile(dir, "lang.yml").toPath(), new UniversalFile(dir, "lang.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath()); Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath());
System.out.println("SubServers > Updated ~/SubServers/lang.yml"); System.out.println("SubServers > Updated ~/SubServers/lang.yml");
@ -707,6 +708,27 @@ public final class SubPlugin extends BungeeCord implements Listener {
} }
} }
@SuppressWarnings("deprecation")
@EventHandler(priority = Byte.MAX_VALUE)
public void fallback(ServerKickEvent e) {
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
int i = 0;
ServerInfo from = e.getKickedFrom();
ServerInfo to = null;
while (to == null || from == to) {
if (e.getPlayer().getPendingConnection().getListener().getServerPriority().size() > i) {
to = getServerInfo(e.getPlayer().getPendingConnection().getListener().getServerPriority().get(i));
} else break;
i++;
}
if (to != null && from != to) {
e.setCancelServer(to);
e.setCancelled(true);
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (to instanceof Server)?((Server) to).getDisplayName():to.getName()).replace("$msg$", e.getKickReason()));
}
}
}
@EventHandler(priority = Byte.MIN_VALUE) @EventHandler(priority = Byte.MIN_VALUE)
public void resetSudo(SubStoppedEvent e) { public void resetSudo(SubStoppedEvent e) {
if (sudo == e.getServer()) { if (sudo == e.getServer()) {

View File

@ -9,10 +9,6 @@
<version>-PLACEHOLDER</version> <version>-PLACEHOLDER</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties>
<galaxi.version>18w37b</galaxi.version>
</properties>
<repositories> <repositories>
<repository> <repository>
<id>me1312-repo</id> <id>me1312-repo</id>
@ -21,18 +17,11 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiAPI</artifactId>
<version>${galaxi.version}</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>net.ME1312.Galaxi</groupId> <groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId> <artifactId>GalaxiEngine</artifactId>
<version>${galaxi.version}</version> <version>18w40a</version>
<scope>compile</scope> <scope>compile</scope>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.msgpack</groupId> <groupId>org.msgpack</groupId>
@ -125,10 +114,6 @@
<outputDirectory>${basedir}/../Javadoc/SubServers.Host</outputDirectory> <outputDirectory>${basedir}/../Javadoc/SubServers.Host</outputDirectory>
<reportOutputDirectory>${basedir}/../Javadoc/SubServers.Host</reportOutputDirectory> <reportOutputDirectory>${basedir}/../Javadoc/SubServers.Host</reportOutputDirectory>
<additionalOptions>-Xdoclint:none</additionalOptions> <additionalOptions>-Xdoclint:none</additionalOptions>
<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>
<dependencySourceInclude>net.ME1312.Galaxi:GalaxiAPI:*</dependencySourceInclude>
</dependencySourceIncludes>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -18,6 +18,7 @@ import net.ME1312.SubServers.Sync.Server.SubServer;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -243,6 +244,27 @@ public final class SubPlugin extends BungeeCord implements Listener {
} }
} }
@SuppressWarnings("deprecation")
@EventHandler(priority = Byte.MAX_VALUE)
public void fallback(ServerKickEvent e) {
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
int i = 0;
ServerInfo from = e.getKickedFrom();
ServerInfo to = null;
while (to == null || from == to) {
if (e.getPlayer().getPendingConnection().getListener().getServerPriority().size() > i) {
to = getServerInfo(e.getPlayer().getPendingConnection().getListener().getServerPriority().get(i));
} else break;
i++;
}
if (to != null && from != to) {
e.setCancelServer(to);
e.setCancelled(true);
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (to instanceof Server)?((Server) to).getDisplayName():to.getName()).replace("$msg$", e.getKickReason()));
}
}
}
@EventHandler(priority = Byte.MIN_VALUE) @EventHandler(priority = Byte.MIN_VALUE)
public void add(SubAddServerEvent e) { public void add(SubAddServerEvent e) {
api.getServer(e.getServer(), server -> { api.getServer(e.getServer(), server -> {