Skip to content

Commit 1538f48

Browse files
committed
Some little changes
1 parent 0ee5d55 commit 1538f48

File tree

11 files changed

+85
-88
lines changed

11 files changed

+85
-88
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
### Things to do:
1212
- [ ] Create a spigot addon that adds connector signs and placeholders
1313
- [ ] Separate the types of connections in classes instead of being in ConnectionIntent
14-
- [ ] Make the plugin API be not so dependent on a instance of PlayerBalancer
14+
- [x] Make the plugin API be not so dependent on a instance of PlayerBalancer
1515
- [ ] Separate connection providers in classes instead of being hardcoded in an enum
16-
- [ ] Make the feature `marker-descs` work per section
1716
- [ ] Implement fast connect (dimension change)
1817
- [ ] Implement a way to redirect premium players to a section and cracked ones to other section (not sure how this works)
1918
- [x] Unify the code that loads serverName into a section (duplicated at SectionManager and ServerSection)

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ public void execute(CommandSender sender, String[] args) {
7979
.color(manager.isPrincipal(section) ? ChatColor.GREEN : ChatColor.RED)
8080
.create());
8181

82+
sender.sendMessage(new ComponentBuilder("Dummy: ")
83+
.color(ChatColor.GRAY)
84+
.append(manager.isDummy(section) ? "yes" : "no")
85+
.color(manager.isDummy(section) ? ChatColor.GREEN : ChatColor.RED)
86+
.create()
87+
);
88+
89+
sender.sendMessage(new ComponentBuilder("Reiterative: ")
90+
.color(ChatColor.GRAY)
91+
.append(manager.isReiterative(section) ? "yes" : "no")
92+
.color(manager.isReiterative(section) ? ChatColor.GREEN : ChatColor.RED)
93+
.create()
94+
);
95+
8296
if (section.getParent() != null) {
8397
sender.sendMessage(new ComponentBuilder("Parent: ")
8498
.color(ChatColor.GRAY)
@@ -111,20 +125,6 @@ public void execute(CommandSender sender, String[] args) {
111125
.create()
112126
);
113127

114-
sender.sendMessage(new ComponentBuilder("Dummy: ")
115-
.color(ChatColor.GRAY)
116-
.append(manager.isDummy(section) ? "yes" : "no")
117-
.color(manager.isDummy(section) ? ChatColor.GREEN : ChatColor.RED)
118-
.create()
119-
);
120-
121-
sender.sendMessage(new ComponentBuilder("Reiterative: ")
122-
.color(ChatColor.GRAY)
123-
.append(manager.isReiterative(section) ? "yes" : "no")
124-
.color(manager.isReiterative(section) ? ChatColor.GREEN : ChatColor.RED)
125-
.create()
126-
);
127-
128128
if (section.getServer() != null) {
129129
sender.sendMessage(new ComponentBuilder("Section Server: ")
130130
.color(ChatColor.GRAY)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.List;
1515
import java.util.concurrent.TimeUnit;
1616

17+
//TODO I don't like this, improve it
1718
public abstract class ConnectionIntent {
1819
protected final PlayerBalancer plugin;
1920
protected final ProxiedPlayer player;

src/main/java/com/jaimemartz/playerbalancer/connection/ProviderType.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
public enum ProviderType {
1414
NONE {
1515
@Override
16-
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
16+
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
1717
return null;
1818
}
1919
},
2020

2121
LOWEST {
2222
@Override
23-
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
23+
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
2424
int min = Integer.MAX_VALUE;
2525
ServerInfo target = null;
2626

27-
for (ServerInfo server : list) {
27+
for (ServerInfo server : servers) {
2828
int count = plugin.getNetworkManager().getPlayers(server);
2929

3030
if (count < min) {
@@ -39,11 +39,11 @@ public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, Li
3939

4040
BALANCED {
4141
@Override
42-
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
42+
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
4343
List<ServerInfo> results = new ArrayList<>();
4444
int min = Integer.MAX_VALUE;
4545

46-
for (ServerInfo server : list) {
46+
for (ServerInfo server : servers) {
4747
int count = plugin.getNetworkManager().getPlayers(server);
4848

4949
if (count <= min) {
@@ -55,38 +55,38 @@ public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, Li
5555
}
5656
}
5757

58-
return results.get(ThreadLocalRandom.current().nextInt(list.size()));
58+
return results.get(ThreadLocalRandom.current().nextInt(servers.size()));
5959
}
6060
},
6161

6262
RANDOM {
6363
@Override
64-
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
65-
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
64+
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
65+
return servers.get(ThreadLocalRandom.current().nextInt(servers.size()));
6666
}
6767
},
6868

6969
PROGRESSIVE {
7070
@Override
71-
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
72-
for (ServerInfo server : list) {
71+
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
72+
for (ServerInfo server : servers) {
7373
ServerStatus status = plugin.getStatusManager().getStatus(server);
7474
if (plugin.getNetworkManager().getPlayers(server) < status.getMaximum()) {
7575
return server;
7676
}
7777
}
7878

79-
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
79+
return servers.get(ThreadLocalRandom.current().nextInt(servers.size()));
8080
}
8181
},
8282

8383
FILLER {
8484
@Override
85-
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
85+
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
8686
int max = Integer.MIN_VALUE;
8787
ServerInfo target = null;
8888

89-
for (ServerInfo server : list) {
89+
for (ServerInfo server : servers) {
9090
ServerStatus status = plugin.getStatusManager().getStatus(server);
9191
int count = plugin.getNetworkManager().getPlayers(server);
9292

@@ -100,5 +100,5 @@ public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, Li
100100
}
101101
};
102102

103-
public abstract ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player);
103+
public abstract ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player);
104104
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
public class ServerAssignRegistry {
1212
private static final Table<ProxiedPlayer, ServerSection, ServerInfo> table = HashBasedTable.create();
1313

14-
public static void assignTarget(ProxiedPlayer player, ServerSection group, ServerInfo server) {
14+
public static void assignTarget(ProxiedPlayer player, ServerSection section, ServerInfo server) {
1515
synchronized (table) {
16-
table.put(player, group, server);
16+
table.put(player, section, server);
1717
}
1818
}
1919

20-
public static void revokeTarget(ProxiedPlayer player, ServerSection group) {
20+
public static void revokeTarget(ProxiedPlayer player, ServerSection section) {
2121
synchronized (table) {
22-
table.remove(player, group);
22+
table.remove(player, section);
2323
}
2424
}
2525

26-
public static ServerInfo getAssignedServer(ProxiedPlayer player, ServerSection group) {
26+
public static ServerInfo getAssignedServer(ProxiedPlayer player, ServerSection section) {
2727
synchronized (table) {
28-
return table.get(player, group);
28+
return table.get(player, section);
2929
}
3030
}
3131

@@ -41,9 +41,9 @@ public static void clearAsssignedServers(ProxiedPlayer player) {
4141
}
4242
}
4343

44-
public static boolean hasAssignedServer(ProxiedPlayer player, ServerSection group) {
44+
public static boolean hasAssignedServer(ProxiedPlayer player, ServerSection section) {
4545
synchronized (table) {
46-
return table.contains(player, group);
46+
return table.contains(player, section);
4747
}
4848
}
4949

src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java

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

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
5-
import com.jaimemartz.playerbalancer.settings.props.shared.CommandProps;
6-
import net.md_5.bungee.api.CommandSender;
75
import net.md_5.bungee.api.connection.ProxiedPlayer;
86

97
public class SectionCommand extends FallbackCommand {
108
private final ServerSection section;
119

12-
public SectionCommand(PlayerBalancer plugin, CommandProps props, ServerSection section) {
13-
super(plugin, props);
10+
public SectionCommand(PlayerBalancer plugin, ServerSection section) {
11+
super(plugin, section.getProps().getCommandProps());
1412
this.section = section;
1513
}
1614

17-
@Override
18-
public void execute(CommandSender sender, String[] args) {
19-
super.execute(sender, args);
20-
}
21-
2215
@Override
2316
public ServerSection getSection(ProxiedPlayer player) {
2417
return section;

src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
55
import com.jaimemartz.playerbalancer.settings.props.shared.SectionProps;
6-
import com.jaimemartz.playerbalancer.utils.FakeServer;
76
import com.jaimemartz.playerbalancer.utils.FixedAdapter;
87
import net.md_5.bungee.api.config.ServerInfo;
98
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -208,7 +207,7 @@ public void execute(String sectionName, SectionProps sectionProps, ServerSection
208207
@Override
209208
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
210209
if (sectionProps.getServerName() != null) {
211-
FakeServer server = new FakeServer(section);
210+
SectionServer server = new SectionServer(section);
212211
section.setServer(server);
213212
plugin.getSectionManager().register(server, section);
214213
FixedAdapter.getFakeServers().put(server.getName(), server);
@@ -219,8 +218,8 @@ public void execute(String sectionName, SectionProps sectionProps, ServerSection
219218
new SectionStage("Section command processing") {
220219
@Override
221220
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
222-
if (sectionProps.getCommand() != null) {
223-
SectionCommand command = new SectionCommand(plugin, sectionProps.getCommand(), section);
221+
if (sectionProps.getCommandProps() != null) {
222+
SectionCommand command = new SectionCommand(plugin, section);
224223
section.setCommand(command);
225224
plugin.getProxy().getPluginManager().registerCommand(plugin, command);
226225
}

src/main/java/com/jaimemartz/playerbalancer/utils/FakeServer.java renamed to src/main/java/com/jaimemartz/playerbalancer/section/SectionServer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.jaimemartz.playerbalancer.utils;
1+
package com.jaimemartz.playerbalancer.section;
22

3-
import com.jaimemartz.playerbalancer.section.ServerSection;
43
import net.md_5.bungee.BungeeServerInfo;
54
import net.md_5.bungee.api.connection.ProxiedPlayer;
65

@@ -9,10 +8,10 @@
98
import java.util.Collection;
109
import java.util.List;
1110

12-
public class FakeServer extends BungeeServerInfo {
11+
public class SectionServer extends BungeeServerInfo {
1312
private final ServerSection section;
1413

15-
public FakeServer(ServerSection section) {
14+
public SectionServer(ServerSection section) {
1615

1716
super(
1817
"@" + section.getProps().getServerName(),

src/main/java/com/jaimemartz/playerbalancer/section/ServerSection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public ServerSection(String name, SectionProps props) {
2727
this.name = name;
2828
this.props = props;
2929

30-
AlphanumComparator<ServerInfo> comparator = new AlphanumComparator<>();
31-
this.servers = Collections.synchronizedSortedSet(new TreeSet<>(comparator));
30+
this.servers = Collections.synchronizedSortedSet(new TreeSet<>((lhs, rhs) ->
31+
AlphanumComparator.getInstance().compare(lhs.getName(), rhs.getName())
32+
));
3233
}
3334

3435
public String getName() {

src/main/java/com/jaimemartz/playerbalancer/settings/props/shared/SectionProps.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class SectionProps {
1717
@Setting(value = "servers")
1818
private List<String> serverEntries;
1919

20-
@Setting(value = "section-command")
21-
private CommandProps command;
20+
@Setting(value = "section-commandProps")
21+
private CommandProps commandProps;
2222

2323
@Setting(value = "section-server")
2424
private String serverName;
@@ -47,12 +47,12 @@ public void setServerEntries(List<String> serverEntries) {
4747
this.serverEntries = serverEntries;
4848
}
4949

50-
public CommandProps getCommand() {
51-
return command;
50+
public CommandProps getCommandProps() {
51+
return commandProps;
5252
}
5353

54-
public void setCommand(CommandProps command) {
55-
this.command = command;
54+
public void setCommandProps(CommandProps commandProps) {
55+
this.commandProps = commandProps;
5656
}
5757

5858
public String getServerName() {
@@ -69,7 +69,7 @@ public String toString() {
6969
"provider=" + provider +
7070
", parentName='" + parentName + '\'' +
7171
", serverEntries=" + serverEntries +
72-
", command=" + command +
72+
", commandProps=" + commandProps +
7373
", serverName='" + serverName + '\'' +
7474
'}';
7575
}

0 commit comments

Comments
 (0)