-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed BungeeCord Load-Balancing. - Now using PlayerSpawnLocationEvent for spigot JoinTP Signed-off-by: Fabricio Winter <[email protected]>
- Loading branch information
1 parent
862b9f1
commit 97a8bca
Showing
12 changed files
with
273 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.notfab.hubbasics.bungee; | ||
|
||
public interface Module { | ||
|
||
void setup(HubBasics hubBasics); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Bungee/src/main/java/net/notfab/hubbasics/bungee/listeners/JoinListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package net.notfab.hubbasics.bungee.listeners; | ||
|
||
import lombok.Getter; | ||
import net.md_5.bungee.api.config.ServerInfo; | ||
import net.md_5.bungee.api.event.ServerConnectEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.event.EventHandler; | ||
import net.notfab.hubbasics.bungee.HubBasics; | ||
import net.notfab.hubbasics.bungee.Module; | ||
import net.notfab.spigot.simpleconfig.SimpleConfig; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.logging.Logger; | ||
|
||
public class JoinListener implements Listener, Module { | ||
|
||
private static final Logger logger = Logger.getLogger("HubBasics"); | ||
private HubBasics hubBasics; | ||
|
||
@Getter | ||
private boolean enabled = false; | ||
private List<String> servers = new ArrayList<>(); | ||
|
||
public JoinListener(HubBasics hubBasics) { | ||
this.hubBasics = hubBasics; | ||
} | ||
|
||
@Override | ||
public void setup(HubBasics hubBasics) { | ||
SimpleConfig config = hubBasics.getConfigManager().getNewConfig("config.yml"); | ||
this.enabled = config.getBoolean("LobbyOnJoin"); | ||
// List of servers | ||
boolean isList = config.get("Lobby") instanceof List; | ||
if (isList) { | ||
for (String server : config.getStringList("Lobby")) { | ||
if (hubBasics.getProxy().getServerInfo(server) == null) { | ||
logger.warning("Unknown Server: " + server); | ||
continue; | ||
} | ||
this.servers.add(server); | ||
} | ||
} else { | ||
String server = config.getString("Lobby"); | ||
if (hubBasics.getProxy().getServerInfo(server) == null) { | ||
logger.warning("Unknown Server: " + server); | ||
return; | ||
} | ||
this.servers.add(server); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onJoin(ServerConnectEvent event) { | ||
if (event.getReason() == ServerConnectEvent.Reason.JOIN_PROXY | ||
|| event.getReason() == ServerConnectEvent.Reason.LOBBY_FALLBACK) { | ||
ServerInfo serverInfo = this.getLobby(); | ||
if (serverInfo != null) { | ||
event.setTarget(serverInfo); | ||
} else { | ||
logger.warning("No available lobby servers!"); | ||
} | ||
} | ||
} | ||
|
||
private ServerInfo getLobby() { | ||
if (this.servers.size() == 1) { | ||
return hubBasics.getProxy().getServerInfo(this.servers.get(0)); | ||
} | ||
int lowest = Integer.MAX_VALUE - 1; | ||
AtomicReference<ServerInfo> serverInfo = new AtomicReference<>(); | ||
this.servers.forEach(lobby -> { | ||
ServerInfo info = hubBasics.getProxy().getServerInfo(lobby); | ||
if (info.getPlayers().size() < lowest) { | ||
serverInfo.set(info); | ||
} | ||
}); | ||
return serverInfo.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,4 @@ task runSpigot(type: JavaExec, dependsOn: copyFiles) { | |
jarFile.getAbsolutePath() | ||
] | ||
debug = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.