Skip to content

Commit 3533077

Browse files
committed
Maybe we don't need custom commands, they will be removed in the next commit
1 parent f3c1029 commit 3533077

File tree

7 files changed

+53
-35
lines changed

7 files changed

+53
-35
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.settings.props.features.CustomFindCommandProps;
5-
import net.md_5.bungee.api.ChatColor;
5+
import com.jaimemartz.playerbalancer.utils.MessageUtils;
66
import net.md_5.bungee.api.CommandSender;
7-
import net.md_5.bungee.api.chat.ComponentBuilder;
7+
import net.md_5.bungee.api.connection.ProxiedPlayer;
88
import net.md_5.bungee.api.plugin.Command;
99

1010
public class CustomFindCommand extends Command {
@@ -28,6 +28,21 @@ private CustomFindCommand(PlayerBalancer plugin, CustomFindCommandProps props) {
2828

2929
@Override
3030
public void execute(CommandSender sender, String[] args) {
31-
sender.sendMessage(new ComponentBuilder("Not implemented yet.").color(ChatColor.RED).create());
31+
if (args.length == 1) {
32+
ProxiedPlayer player = plugin.getProxy().getPlayer(args[0]);
33+
34+
if (player != null && player.getServer() != null) {
35+
MessageUtils.send(player, props.getFormats().getResult(), (str) ->
36+
str.replace("{server}", player.getServer().getInfo().getName())
37+
.replace("{name}", player.getName())
38+
);
39+
} else {
40+
MessageUtils.send(player, props.getFormats().getMissing(), (str) ->
41+
str.replace("{name}", player.getName())
42+
);
43+
}
44+
} else {
45+
MessageUtils.send(sender, props.getFormats().getUsage());
46+
}
3247
}
3348
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.util.Map;
1010

11-
//todo improve this
1211
public class ServerAssignRegistry {
1312
private static final Table<ProxiedPlayer, ServerSection, ServerInfo> table = HashBasedTable.create();
1413

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import net.md_5.bungee.event.EventHandler;
1616
import net.md_5.bungee.event.EventPriority;
1717

18-
import java.util.Optional;
18+
import java.util.Map;
1919

2020
public class ServerConnectListener implements Listener {
2121
private final PlayerBalancer plugin;
@@ -64,17 +64,29 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
6464

6565
if (section != null) {
6666
if (permissionRouterProps.isEnabled()) {
67-
Optional<String> bindName = permissionRouterProps.getRouteBind(player, section);
68-
if (bindName.isPresent()) {
69-
ServerSection bind = plugin.getSectionManager().getByName(bindName.get());
70-
if (bind != null) {
71-
return bind;
67+
Map<String, String> routes = permissionRouterProps.getRules().get(section.getName());
68+
69+
if (routes != null) {
70+
for (Map.Entry<String, String> route : routes.entrySet()) {
71+
if (player.hasPermission(route.getKey())) {
72+
ServerSection bind = plugin.getSectionManager().getByName(route.getValue());
73+
ServerSection current = plugin.getSectionManager().getByPlayer(player);
74+
75+
if (bind != null) {
76+
if (current == bind)
77+
break;
78+
79+
return bind;
80+
}
81+
82+
break;
83+
}
7284
}
7385
}
7486
}
7587

7688
//Checks only for servers (not the section server)
77-
if (section.getServers().contains(target)) {
89+
if (!target.equals(section.getServer())) {
7890
if (plugin.getSectionManager().isDummy(section)) {
7991
return null;
8092
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ public ServerStatus getStatus(ServerInfo server) {
9898
}
9999

100100
public boolean isAccessible(ServerInfo server) {
101-
if (overriders.containsKey(server)) {
102-
return overriders.get(server);
101+
Boolean override = overriders.get(server);
102+
103+
if (override != null) {
104+
return override;
103105
}
104106

105107
ServerStatus status = getStatus(server);

Main Plugin/src/main/java/com/jaimemartz/playerbalancer/settings/props/features/CustomFindCommandProps.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ public class CustomFindCommandProps {
1919

2020
@ConfigSerializable
2121
@Data
22-
private static class Formats {
22+
public static class Formats {
2323
@Setting
2424
private String result;
2525

2626
@Setting
27-
private String offline;
27+
private String missing;
28+
29+
@Setting
30+
private String usage;
2831
}
2932
}
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.jaimemartz.playerbalancer.settings.props.features;
22

3-
import com.jaimemartz.playerbalancer.section.ServerSection;
43
import lombok.Data;
5-
import net.md_5.bungee.api.connection.ProxiedPlayer;
64
import ninja.leaping.configurate.objectmapping.Setting;
75
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
86

97
import java.util.Map;
10-
import java.util.Optional;
118

129
@ConfigSerializable
1310
@Data
@@ -17,18 +14,4 @@ public class PermissionRouterProps {
1714

1815
@Setting
1916
private Map<String, Map<String, String>> rules;
20-
21-
public Optional<String> getRouteBind(ProxiedPlayer player, ServerSection section) {
22-
Map<String, String> routes = rules.get(section.getName());
23-
24-
if (routes != null) {
25-
for (Map.Entry<String, String> route : routes.entrySet()) {
26-
if (player.hasPermission(route.getKey())) {
27-
return Optional.of(route.getValue());
28-
}
29-
}
30-
}
31-
32-
return Optional.empty();
33-
}
3417
}

Main Plugin/src/main/resources/default.conf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ features {
112112
dummy-sections=[]
113113

114114
# Reiterative sections remember the server the player connected to previously
115-
# The plugin will keep connecting the player to that server until a change occurs
115+
# The plugin will keep connecting the player to that server repeatedly
116116
reiterative-sections=[]
117117

118118
# When true, section servers will show the sum of the players on all servers on that section
@@ -225,21 +225,24 @@ features {
225225
custom-find-command {
226226
enabled=false
227227

228+
# Leave permission empty for no permission
228229
command {
229230
name=find
230231
permission=""
231232
aliases=[]
232233
}
233234

234235
formats {
235-
result=""
236-
offline=""
236+
result="&a{name} &cis online at &a{server}"
237+
missing="&cThere is no such player named {name}"
238+
usage="&cUsage: /find <user>"
237239
}
238240
}
239241

240242
custom-list-command {
241243
enabled=false
242244

245+
# Leave permission empty for no permission
243246
command {
244247
name=glist
245248
permission=""
@@ -255,6 +258,7 @@ features {
255258
custom-server-command {
256259
enabled=false
257260

261+
# Leave permission empty for no permission
258262
command {
259263
name=server
260264
permission=""

0 commit comments

Comments
 (0)