Skip to content

Commit 24953e5

Browse files
committed
Parameter for section commands and improvements to the ping manager
1 parent 5df10a5 commit 24953e5

File tree

19 files changed

+265
-94
lines changed

19 files changed

+265
-94
lines changed

.idea/misc.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.jaimemartz</groupId>
88
<artifactId>lobbybalancer</artifactId>
9-
<version>2.0.9.4</version>
9+
<version>2.0.9.5</version>
1010
<name>LobbyBalancer</name>
1111

1212
<properties>

src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void execute(CommandSender sender, String[] args) {
7979
try {
8080
ServerSection section = callable.call();
8181
if (section != null) {
82-
ConnectionIntent.connect(plugin, player, section);
82+
ConnectionIntent.simple(plugin, player, section);
8383
}
8484
} catch (Exception e) {
8585
//Nothing to do

src/main/java/me/jaimemartz/lobbybalancer/commands/MainCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public void execute(final CommandSender sender, String[] args) {
3232
switch (args[0]) {
3333
case "paste": {
3434
if (sender.hasPermission("lobbybalancer.admin")) {
35-
PasteHelper.LOGS.send(plugin, sender, "Last log file paste link: {link}");
3635
PasteHelper.PLUGIN.send(plugin, sender, "Plugin config paste link: {link}");
3736
PasteHelper.BUNGEE.send(plugin, sender, "Bungee config paste link (sensitive): {link}");
3837
} else {

src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import me.jaimemartz.lobbybalancer.LobbyBalancer;
77
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
88
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
9-
import me.jaimemartz.lobbybalancer.ping.ServerStatus;
9+
import me.jaimemartz.lobbybalancer.ping.PingStatus;
1010
import me.jaimemartz.lobbybalancer.section.ServerSection;
1111
import net.md_5.bungee.api.ChatColor;
1212
import net.md_5.bungee.api.CommandSender;
@@ -35,21 +35,21 @@ public void execute(CommandSender sender, String[] args) {
3535
if (sender.hasPermission("lobbybalancer.admin")) {
3636
if (args.length != 0) {
3737
switch (args[0].toLowerCase()) {
38-
case "connect": {
38+
case "simple": {
3939
if (args.length >= 2) {
4040
String input = args[1];
4141
ServerSection section = plugin.getSectionManager().getByName(input);
4242
if (section != null) {
4343
if (args.length == 3) {
4444
ProxiedPlayer player = plugin.getProxy().getPlayer(args[2]);
4545
if (player != null) {
46-
ConnectionIntent.connect(plugin, player, section);
46+
ConnectionIntent.simple(plugin, player, section);
4747
} else {
4848
msgr.send("&cThere is no player with that name connected to this proxy");
4949
}
5050
} else {
5151
if (sender instanceof ProxiedPlayer) {
52-
ConnectionIntent.connect(plugin, (ProxiedPlayer) sender, section);
52+
ConnectionIntent.simple(plugin, (ProxiedPlayer) sender, section);
5353
} else {
5454
msgr.send("&cThis command can only be executed by a player");
5555
}
@@ -117,7 +117,7 @@ public void execute(CommandSender sender, String[] args) {
117117
if (!section.getServers().isEmpty()) {
118118
msgr.send("&7Section Servers: ");
119119
section.getServers().forEach(server -> {
120-
ServerStatus status = plugin.getPingManager().getStatus(server);
120+
PingStatus status = plugin.getPingManager().getStatus(server);
121121
msgr.send("&7> Server &b{name} &c({connected}/{maximum}) &7({status}&7)",
122122
new Replacement("{name}", server.getName()),
123123
new Replacement("{connected}", String.valueOf(status.getOnlinePlayers())),
@@ -191,7 +191,7 @@ public void execute(CommandSender sender, String[] args) {
191191
"&7Available commands:",
192192
"&3/section list &7- &cTells you which sections are configured in the plugin",
193193
"&3/section info <section> &7- &cTells you info about the section",
194-
"&3/section connect <section> [player] &7- &cConnects you or the specified player to that section",
194+
"&3/section simple <section> [player] &7- &cConnects you or the specified player to that section",
195195
"&7&m-----------------------------------------------------"
196196
);
197197
}

src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public class ConfigEntries implements ConfigEntryHolder {
4747

4848
public static final ConfigEntry<String> CONNECTING_MESSAGE = new ConfigEntry<>(0, "settings.messages.connecting", null);
4949
public static final ConfigEntry<String> FAILURE_MESSAGE = new ConfigEntry<>(0, "settings.messages.failure", null);
50-
public static final ConfigEntry<String> UNAVAILABLE_MESSAGE = new ConfigEntry<>(0, "settings.messages.unavailable", null);
51-
public static final ConfigEntry<String> UNKNOWN_SECTION_MESSAGE = new ConfigEntry<>(0, "settings.messages.unknown", null);
50+
public static final ConfigEntry<String> UNKNOWN_SECTION_MESSAGE = new ConfigEntry<>(0, "settings.messages.unknown-section", null);
51+
public static final ConfigEntry<String> INVALID_INPUT_MESSAGE = new ConfigEntry<>(0, "settings.messages.invalid-input", null);
52+
public static final ConfigEntry<String> UNAVAILABLE_MESSAGE = new ConfigEntry<>(0, "settings.messages.unavailable-server", null);
5253
public static final ConfigEntry<String> KICK_MESSAGE = new ConfigEntry<>(0, "settings.messages.kick", null);
5354

5455
public static final ConfigEntry<String> CONFIG_VERSION = new ConfigEntry<>(0, "version", null);

src/main/java/me/jaimemartz/lobbybalancer/connection/ConnectionIntent.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import me.jaimemartz.lobbybalancer.LobbyBalancer;
66
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
77
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
8-
import me.jaimemartz.lobbybalancer.ping.ServerStatus;
8+
import me.jaimemartz.lobbybalancer.ping.PingStatus;
99
import me.jaimemartz.lobbybalancer.section.ServerSection;
1010
import net.md_5.bungee.api.config.ServerInfo;
1111
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -32,7 +32,7 @@ public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType
3232
ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
3333
if (target != null) {
3434
new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName()));
35-
this.connect(target);
35+
this.simple(target);
3636
} else {
3737
new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get());
3838
this.failure();
@@ -56,7 +56,7 @@ private ServerInfo fetchServer(LobbyBalancer plugin, ProxiedPlayer player, Serve
5656
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
5757
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
5858
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
59-
ServerStatus status = plugin.getPingManager().getStatus(target);
59+
PingStatus status = plugin.getPingManager().getStatus(target);
6060
if (status.isAccessible()) {
6161
return target;
6262
} else {
@@ -73,7 +73,7 @@ private ServerInfo fetchServer(LobbyBalancer plugin, ProxiedPlayer player, Serve
7373
ServerInfo target = provider.requestTarget(plugin, section, servers, player);
7474
if (target == null) continue;
7575

76-
ServerStatus status = plugin.getPingManager().getStatus(target);
76+
PingStatus status = plugin.getPingManager().getStatus(target);
7777
if (status.isAccessible()) {
7878
return target;
7979
} else {
@@ -84,22 +84,26 @@ private ServerInfo fetchServer(LobbyBalancer plugin, ProxiedPlayer player, Serve
8484
return null;
8585
}
8686

87-
public abstract void connect(ServerInfo server);
87+
public abstract void simple(ServerInfo server);
8888

8989
public void failure() {
9090
//Nothing to do
9191
}
9292

93-
public static void connect(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
93+
public static void simple(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
9494
new ConnectionIntent(plugin, player, section) {
9595
@Override
96-
public void connect(ServerInfo server) {
97-
PlayerLocker.lock(player);
98-
player.connect(server);
99-
plugin.getProxy().getScheduler().schedule(plugin, () -> {
100-
PlayerLocker.unlock(player);
101-
}, 5, TimeUnit.SECONDS);
96+
public void simple(ServerInfo server) {
97+
direct(plugin, player, server);
10298
}
10399
};
104100
}
101+
102+
public static void direct(LobbyBalancer plugin, ProxiedPlayer player, ServerInfo server) {
103+
PlayerLocker.lock(player);
104+
player.connect(server);
105+
plugin.getProxy().getScheduler().schedule(plugin, () -> {
106+
PlayerLocker.unlock(player);
107+
}, 5, TimeUnit.SECONDS);
108+
}
105109
}

src/main/java/me/jaimemartz/lobbybalancer/connection/ProviderType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import me.jaimemartz.lobbybalancer.LobbyBalancer;
88
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
99
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
10-
import me.jaimemartz.lobbybalancer.ping.ServerStatus;
10+
import me.jaimemartz.lobbybalancer.ping.PingStatus;
1111
import me.jaimemartz.lobbybalancer.section.ServerSection;
1212
import net.md_5.bungee.api.config.ServerInfo;
1313
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -95,7 +95,7 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
9595
@Override
9696
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
9797
for (ServerInfo server : list) {
98-
ServerStatus status = plugin.getPingManager().getStatus(server);
98+
PingStatus status = plugin.getPingManager().getStatus(server);
9999
if (NetworkManager.getPlayers(server).size() < status.getMaximumPlayers()) {
100100
return server;
101101
}
@@ -111,7 +111,7 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
111111
ServerInfo target = null;
112112

113113
for (ServerInfo server : list) {
114-
ServerStatus status = plugin.getPingManager().getStatus(server);
114+
PingStatus status = plugin.getPingManager().getStatus(server);
115115
int count = NetworkManager.getPlayers(server).size();
116116

117117
if (count > max && count <= status.getMaximumPlayers()) {

src/main/java/me/jaimemartz/lobbybalancer/listener/PluginMessageListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void onPluginMessage(PluginMessageEvent event) {
4646
return;
4747
}
4848

49-
ConnectionIntent.connect(plugin, player, section);
49+
ConnectionIntent.simple(plugin, player, section);
5050
}
5151
break;
5252
}
@@ -62,7 +62,7 @@ public void onPluginMessage(PluginMessageEvent event) {
6262
return;
6363
}
6464

65-
ConnectionIntent.connect(plugin, player, section);
65+
ConnectionIntent.simple(plugin, player, section);
6666
break;
6767
}
6868

src/main/java/me/jaimemartz/lobbybalancer/listener/ServerConnectListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void onConnect(ServerConnectEvent event) {
6565
if (section != null) {
6666
new ConnectionIntent(plugin, player, section) {
6767
@Override
68-
public void connect(ServerInfo server) {
68+
public void simple(ServerInfo server) {
6969
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
7070
ServerAssignRegistry.assignTarget(player, section, server);
7171
}

0 commit comments

Comments
 (0)