Skip to content

Commit f3c1029

Browse files
committed
Added aliases, permission router, and progress for custom commands
1 parent c582c05 commit f3c1029

20 files changed

+174
-54
lines changed

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

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.jaimemartz.playerbalancer;
22

33
import com.google.common.reflect.TypeToken;
4-
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
5-
import com.jaimemartz.playerbalancer.commands.MainCommand;
6-
import com.jaimemartz.playerbalancer.commands.ManageCommand;
4+
import com.jaimemartz.playerbalancer.commands.*;
75
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
6+
import com.jaimemartz.playerbalancer.helper.NetworkManager;
7+
import com.jaimemartz.playerbalancer.helper.PasteHelper;
8+
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
89
import com.jaimemartz.playerbalancer.listeners.*;
9-
import com.jaimemartz.playerbalancer.manager.NetworkManager;
10-
import com.jaimemartz.playerbalancer.manager.PasteHelper;
11-
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
1210
import com.jaimemartz.playerbalancer.ping.StatusManager;
1311
import com.jaimemartz.playerbalancer.section.SectionManager;
1412
import com.jaimemartz.playerbalancer.settings.SettingsHolder;
@@ -41,7 +39,7 @@ public class PlayerBalancer extends Plugin {
4139
private final StringBuilder logsBuilder = new StringBuilder();
4240

4341
private FallbackCommand fallbackCommand;
44-
private Command mainCommand, manageCommand;
42+
private Command mainCommand, manageCommand, findCommand, listCommand, serverCommand;
4543
private Listener connectListener, kickListener, reloadListener, pluginMessageListener;
4644

4745
@Override
@@ -181,23 +179,27 @@ private void execStart() {
181179
getProxy().getPluginManager().registerListener(this, kickListener);
182180
}
183181

182+
//After the modules have loaded (hopefully?)
184183
getProxy().getScheduler().schedule(this, () -> {
185184
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-
}
185+
tryUnregisterCommands("cmd_find");
186+
findCommand = new CustomFindCommand(this);
187+
getProxy().getPluginManager().registerCommand(this, findCommand);
191188
}
192189

193190
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-
}
191+
tryUnregisterCommands("cmd_list");
192+
listCommand = new CustomListCommand(this);
193+
getProxy().getPluginManager().registerCommand(this, listCommand);
199194
}
200-
}, 1L, TimeUnit.SECONDS);
195+
196+
if (settings.getFeaturesProps().getCustomServerCommandProps().isEnabled()) {
197+
tryUnregisterCommands("cmd_server");
198+
serverCommand = new CustomServerCommand(this);
199+
getProxy().getPluginManager().registerCommand(this, serverCommand);
200+
}
201+
202+
}, 5L, TimeUnit.SECONDS);
201203

202204
PasteHelper.reset();
203205
getLogger().info("The plugin has finished loading without any problems");
@@ -214,6 +216,16 @@ private void execStart() {
214216
}
215217
}
216218

219+
private void tryUnregisterCommands(String pluginName) {
220+
Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName);
221+
if (plugin != null) {
222+
getProxy().getPluginManager().unregisterCommands(plugin);
223+
getLogger().info("Unregistered all commands of the plugin: " + pluginName);
224+
} else {
225+
getLogger().warning("Could not find the plugin: " + pluginName);
226+
}
227+
}
228+
217229
private void execStop() {
218230
if (mainCommand != null) {
219231
getProxy().getPluginManager().unregisterCommand(mainCommand);
@@ -269,6 +281,27 @@ private void execStop() {
269281
manageCommand = null;
270282
}
271283

284+
if (settings.getFeaturesProps().getCustomFindCommandProps().isEnabled()) {
285+
if (findCommand != null) {
286+
getProxy().getPluginManager().unregisterCommand(findCommand);
287+
findCommand = null;
288+
}
289+
}
290+
291+
if (settings.getFeaturesProps().getCustomListCommandProps().isEnabled()) {
292+
if (listCommand != null) {
293+
getProxy().getPluginManager().unregisterCommand(listCommand);
294+
listCommand = null;
295+
}
296+
}
297+
298+
if (settings.getFeaturesProps().getCustomServerCommandProps().isEnabled()) {
299+
if (serverCommand != null) {
300+
getProxy().getPluginManager().unregisterCommand(serverCommand);
301+
serverCommand = null;
302+
}
303+
}
304+
272305
if (sectionManager != null) {
273306
sectionManager.flush();
274307
}

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/custom/CustomFindCommand.java renamed to Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomFindCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.jaimemartz.playerbalancer.commands.custom;
1+
package com.jaimemartz.playerbalancer.commands;
22

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.settings.props.features.CustomFindCommandProps;

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/custom/CustomListCommand.java renamed to Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomListCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.jaimemartz.playerbalancer.commands.custom;
1+
package com.jaimemartz.playerbalancer.commands;
22

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.settings.props.features.CustomListCommandProps;

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/custom/CustomServerCommand.java renamed to Main Plugin/src/main/java/com/jaimemartz/playerbalancer/commands/CustomServerCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.jaimemartz.playerbalancer.commands.custom;
1+
package com.jaimemartz.playerbalancer.commands;
22

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.settings.props.features.CustomServerCommandProps;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,16 @@ public ServerSection getSection(ProxiedPlayer player) {
8787
return null;
8888
}
8989

90-
ServerSection target = plugin.getSectionManager().getBind(props.getRules(), current)
91-
.orElse(current.getParent());
90+
ServerSection target = current.getParent();
91+
92+
String bindName = props.getRules().get(current.getName());
93+
if (bindName != null) {
94+
ServerSection bind = plugin.getSectionManager().getByName(bindName);
95+
if (bind != null) {
96+
target = bind;
97+
}
98+
}
99+
92100
if (target == null) {
93101
MessageUtils.send(player, messages.getUnavailableServerMessage());
94102
return null;

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

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

33
import com.google.common.base.Strings;
44
import com.jaimemartz.playerbalancer.PlayerBalancer;
5-
import com.jaimemartz.playerbalancer.manager.PasteHelper;
5+
import com.jaimemartz.playerbalancer.helper.PasteHelper;
66
import net.md_5.bungee.api.ChatColor;
77
import net.md_5.bungee.api.CommandSender;
88
import net.md_5.bungee.api.chat.ClickEvent;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public void execute(CommandSender sender, String[] args) {
109109
.create());
110110
}
111111

112+
sender.sendMessage(new ComponentBuilder("Alias: ")
113+
.color(ChatColor.GRAY)
114+
.append(String.valueOf(section.getProps().getAlias()))
115+
.color(ChatColor.AQUA)
116+
.create()
117+
);
118+
112119
sender.sendMessage(new ComponentBuilder("Position: ")
113120
.color(ChatColor.GRAY)
114121
.append(String.valueOf(section.getPosition()))

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.jaimemartz.playerbalancer.connection;
22

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
4-
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
4+
import com.jaimemartz.playerbalancer.helper.PlayerLocker;
55
import com.jaimemartz.playerbalancer.section.ServerSection;
66
import com.jaimemartz.playerbalancer.utils.MessageUtils;
77
import net.md_5.bungee.api.Callback;
@@ -26,6 +26,7 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderTyp
2626

2727
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(),
2828
(str) -> str.replace("{section}", section.getName())
29+
.replace("{alias}", section.getProps().getAlias())
2930
);
3031

3132
//Prevents removing servers from the section
@@ -46,6 +47,8 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderTyp
4647
if (response) { //only if the connect has been executed correctly
4748
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectedMessage(),
4849
(str) -> str.replace("{server}", target.getName())
50+
.replace("{section}", section.getName())
51+
.replace("{alias}", section.getProps().getAlias())
4952
);
5053
}
5154
});

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/manager/NetworkManager.java renamed to Main Plugin/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.jaimemartz.playerbalancer.manager;
1+
package com.jaimemartz.playerbalancer.helper;
22

33
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
44
import com.jaimemartz.playerbalancer.PlayerBalancer;

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/manager/PasteHelper.java renamed to Main Plugin/src/main/java/com/jaimemartz/playerbalancer/helper/PasteHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.jaimemartz.playerbalancer.manager;
1+
package com.jaimemartz.playerbalancer.helper;
22

33
import com.google.common.io.CharStreams;
44
import com.jaimemartz.playerbalancer.PlayerBalancer;

0 commit comments

Comments
 (0)