Skip to content

Commit c582c05

Browse files
committed
Restructured some classes, progress for custom commands
1 parent e973501 commit c582c05

19 files changed

+276
-115
lines changed

Main Plugin/pom.xml

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

1212
<name>PlayerBalancer Plugin</name>
1313
<artifactId>playerbalancer-plugin</artifactId>
14-
<version>2.1.4.4</version>
14+
<version>2.1.5</version>
1515

1616
<build>
1717
<finalName>PlayerBalancer</finalName>

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.net.URL;
2727
import java.net.URLConnection;
2828
import java.nio.file.Files;
29+
import java.util.concurrent.TimeUnit;
2930
import java.util.logging.Handler;
3031
import java.util.logging.Level;
3132
import java.util.logging.LogRecord;
@@ -149,11 +150,11 @@ private void execStart() {
149150

150151
statusManager = new StatusManager(this);
151152

152-
if (settings.getServerCheckerProps().isEnabled()) {
153+
if (settings.getFeaturesProps().getServerCheckerProps().isEnabled()) {
153154
statusManager.start();
154155
}
155156

156-
if (settings.getFallbackCommandProps().isEnabled()) {
157+
if (settings.getFeaturesProps().getFallbackCommandProps().isEnabled()) {
157158
fallbackCommand = new FallbackCommand(this);
158159
getProxy().getPluginManager().registerCommand(this, fallbackCommand);
159160
}
@@ -175,13 +176,30 @@ private void execStart() {
175176

176177
getProxy().getPluginManager().registerListener(this, new PlayerDisconnectListener(this));
177178

178-
PasteHelper.reset();
179-
180-
if (settings.getKickHandlerProps().isEnabled()) {
179+
if (settings.getFeaturesProps().getKickHandlerProps().isEnabled()) {
181180
kickListener = new ServerKickListener(this);
182181
getProxy().getPluginManager().registerListener(this, kickListener);
183182
}
184183

184+
getProxy().getScheduler().schedule(this, () -> {
185+
if (settings.getFeaturesProps().getCustomFindCommandProps().isEnabled()) {
186+
Plugin plugin = getProxy().getPluginManager().getPlugin("cmd_find");
187+
if (plugin != null) {
188+
getProxy().getPluginManager().unregisterCommands(plugin);
189+
getLogger().info("Unregistered commands of the plugin: " + plugin.getDescription().getName());
190+
}
191+
}
192+
193+
if (settings.getFeaturesProps().getCustomListCommandProps().isEnabled()) {
194+
Plugin plugin = getProxy().getPluginManager().getPlugin("cmd_list");
195+
if (plugin != null) {
196+
getProxy().getPluginManager().unregisterCommands(plugin);
197+
getLogger().info("Unregistered commands of the plugin: " + plugin.getDescription().getName());
198+
}
199+
}
200+
}, 1L, TimeUnit.SECONDS);
201+
202+
PasteHelper.reset();
185203
getLogger().info("The plugin has finished loading without any problems");
186204
} else {
187205
getLogger().warning("-----------------------------------------------------");
@@ -213,20 +231,20 @@ private void execStop() {
213231
}
214232
}
215233

216-
if (settings.getServerCheckerProps().isEnabled()) {
234+
if (settings.getFeaturesProps().getServerCheckerProps().isEnabled()) {
217235
if (statusManager != null) {
218236
statusManager.stop();
219237
}
220238
}
221239

222-
if (settings.getFallbackCommandProps().isEnabled()) {
240+
if (settings.getFeaturesProps().getFallbackCommandProps().isEnabled()) {
223241
if (fallbackCommand != null) {
224242
getProxy().getPluginManager().unregisterCommand(fallbackCommand);
225243
fallbackCommand = null;
226244
}
227245
}
228246

229-
if (settings.getKickHandlerProps().isEnabled()) {
247+
if (settings.getFeaturesProps().getKickHandlerProps().isEnabled()) {
230248
if (kickListener != null) {
231249
getProxy().getPluginManager().unregisterListener(kickListener);
232250
kickListener = null;

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class FallbackCommand extends Command {
2525
* Constructor for `fallback-command`
2626
*/
2727
public FallbackCommand(PlayerBalancer plugin) {
28-
this(plugin, plugin.getSettings().getFallbackCommandProps().getCommand());
28+
this(plugin, plugin.getSettings().getFeaturesProps().getFallbackCommandProps().getCommand());
2929
}
3030

3131
/**
@@ -34,7 +34,7 @@ public FallbackCommand(PlayerBalancer plugin) {
3434
public FallbackCommand(PlayerBalancer plugin, CommandProps commandProps) {
3535
super(commandProps.getName(), commandProps.getPermission(), commandProps.getAliasesArray());
3636
this.messages = plugin.getSettings().getMessagesProps();
37-
this.props = plugin.getSettings().getFallbackCommandProps();
37+
this.props = plugin.getSettings().getFeaturesProps().getFallbackCommandProps();
3838
this.plugin = plugin;
3939
}
4040

@@ -103,7 +103,7 @@ public ServerSection getSection(ProxiedPlayer player) {
103103

104104
return target;
105105
} else {
106-
if (plugin.getSettings().getBalancerProps().isDefaultPrincipal()) {
106+
if (plugin.getSettings().getFeaturesProps().getBalancerProps().isDefaultPrincipal()) {
107107
return plugin.getSectionManager().getPrincipal();
108108
} else {
109109
MessageUtils.send(player, messages.getUnavailableServerMessage());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.jaimemartz.playerbalancer.commands.custom;
2+
3+
import com.jaimemartz.playerbalancer.PlayerBalancer;
4+
import com.jaimemartz.playerbalancer.settings.props.features.CustomFindCommandProps;
5+
import net.md_5.bungee.api.ChatColor;
6+
import net.md_5.bungee.api.CommandSender;
7+
import net.md_5.bungee.api.chat.ComponentBuilder;
8+
import net.md_5.bungee.api.plugin.Command;
9+
10+
public class CustomFindCommand extends Command {
11+
private final PlayerBalancer plugin;
12+
private final CustomFindCommandProps props;
13+
14+
public CustomFindCommand(PlayerBalancer plugin) {
15+
this(plugin, plugin.getSettings().getFeaturesProps().getCustomFindCommandProps());
16+
}
17+
18+
private CustomFindCommand(PlayerBalancer plugin, CustomFindCommandProps props) {
19+
super(
20+
props.getCommand().getName(),
21+
props.getCommand().getPermission(),
22+
props.getCommand().getAliasesArray()
23+
);
24+
25+
this.plugin = plugin;
26+
this.props = props;
27+
}
28+
29+
@Override
30+
public void execute(CommandSender sender, String[] args) {
31+
sender.sendMessage(new ComponentBuilder("Not implemented yet.").color(ChatColor.RED).create());
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.jaimemartz.playerbalancer.commands.custom;
2+
3+
import com.jaimemartz.playerbalancer.PlayerBalancer;
4+
import com.jaimemartz.playerbalancer.settings.props.features.CustomListCommandProps;
5+
import net.md_5.bungee.api.ChatColor;
6+
import net.md_5.bungee.api.CommandSender;
7+
import net.md_5.bungee.api.chat.ComponentBuilder;
8+
import net.md_5.bungee.api.plugin.Command;
9+
10+
public class CustomListCommand extends Command {
11+
private final PlayerBalancer plugin;
12+
private final CustomListCommandProps props;
13+
14+
public CustomListCommand(PlayerBalancer plugin) {
15+
this(plugin, plugin.getSettings().getFeaturesProps().getCustomListCommandProps());
16+
}
17+
18+
private CustomListCommand(PlayerBalancer plugin, CustomListCommandProps props) {
19+
super(
20+
props.getCommand().getName(),
21+
props.getCommand().getPermission(),
22+
props.getCommand().getAliasesArray()
23+
);
24+
25+
this.plugin = plugin;
26+
this.props = props;
27+
}
28+
29+
@Override
30+
public void execute(CommandSender sender, String[] args) {
31+
sender.sendMessage(new ComponentBuilder("Not implemented yet.").color(ChatColor.RED).create());
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.jaimemartz.playerbalancer.commands.custom;
2+
3+
import com.jaimemartz.playerbalancer.PlayerBalancer;
4+
import com.jaimemartz.playerbalancer.settings.props.features.CustomServerCommandProps;
5+
import net.md_5.bungee.api.ChatColor;
6+
import net.md_5.bungee.api.CommandSender;
7+
import net.md_5.bungee.api.chat.ComponentBuilder;
8+
import net.md_5.bungee.api.plugin.Command;
9+
10+
public class CustomServerCommand extends Command {
11+
private final PlayerBalancer plugin;
12+
private final CustomServerCommandProps props;
13+
14+
public CustomServerCommand(PlayerBalancer plugin) {
15+
this(plugin, plugin.getSettings().getFeaturesProps().getCustomServerCommandProps());
16+
}
17+
18+
private CustomServerCommand(PlayerBalancer plugin, CustomServerCommandProps props) {
19+
super(
20+
props.getCommand().getName(),
21+
props.getCommand().getPermission(),
22+
props.getCommand().getAliasesArray()
23+
);
24+
25+
this.plugin = plugin;
26+
this.props = props;
27+
}
28+
29+
@Override
30+
public void execute(CommandSender sender, String[] args) {
31+
sender.sendMessage(new ComponentBuilder("Not implemented yet.").color(ChatColor.RED).create());
32+
}
33+
}

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private ServerInfo fetchServer(ProxiedPlayer player, ServerSection section, Prov
7979
}
8080
}
8181

82-
int intents = plugin.getSettings().getServerCheckerProps().getAttempts();
82+
int intents = plugin.getSettings().getFeaturesProps().getServerCheckerProps().getAttempts();
8383
for (int intent = 1; intent <= intents; intent++) {
8484
if (servers.size() == 0) return null;
8585

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerKickListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ServerKickListener implements Listener {
2626
private final PlayerBalancer plugin;
2727

2828
public ServerKickListener(PlayerBalancer plugin) {
29-
this.props = plugin.getSettings().getKickHandlerProps();
29+
this.props = plugin.getSettings().getFeaturesProps().getKickHandlerProps();
3030
this.messages = plugin.getSettings().getMessagesProps();
3131
this.plugin = plugin;
3232
}
@@ -126,7 +126,7 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo from) {
126126

127127
return target;
128128
} else {
129-
if (plugin.getSettings().getBalancerProps().isDefaultPrincipal()) {
129+
if (plugin.getSettings().getFeaturesProps().getBalancerProps().isDefaultPrincipal()) {
130130
return plugin.getSectionManager().getPrincipal();
131131
} else {
132132
MessageUtils.send(player, messages.getUnavailableServerMessage());

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/PingTactic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void ping(ServerInfo server, Callback<ServerStatus> callback, PlayerBalan
1818
try {
1919
StatusResponse response = utility.ping(
2020
server.getAddress(),
21-
plugin.getSettings().getServerCheckerProps().getTimeout());
21+
plugin.getSettings().getFeaturesProps().getServerCheckerProps().getTimeout());
2222
callback.done(new ServerStatus(
2323
response.getDescription().toLegacyText(),
2424
response.getPlayers().getOnline(),

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class StatusManager implements Listener {
2929
private final Map<ServerInfo, Boolean> overriders = new HashMap<>();
3030

3131
public StatusManager(PlayerBalancer plugin) {
32-
this.props = plugin.getSettings().getServerCheckerProps();
32+
this.props = plugin.getSettings().getFeaturesProps().getServerCheckerProps();
3333
this.plugin = plugin;
3434
}
3535

0 commit comments

Comments
 (0)