Skip to content

Commit a6c2470

Browse files
committed
Started using lombok for getters and setters
Will try to use a dependency injector in next commits
1 parent 1fd5b38 commit a6c2470

File tree

9 files changed

+66
-197
lines changed

9 files changed

+66
-197
lines changed

lobbybalancer.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@
4141
<orderEntry type="library" name="Maven: org.bstats:bstats-bungeecord:1.2-SNAPSHOT" level="project" />
4242
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
4343
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
44+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
4445
</component>
4546
</module>

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,11 @@
114114
<version>4.12</version>
115115
<scope>test</scope>
116116
</dependency>
117+
<dependency>
118+
<groupId>org.projectlombok</groupId>
119+
<artifactId>lombok</artifactId>
120+
<version>1.16.16</version>
121+
<scope>provided</scope>
122+
</dependency>
117123
</dependencies>
118124
</project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void execute(CommandSender sender, String[] args) {
4242
ServerSection target = plugin.getSectionManager().getByName(bind);
4343

4444
if (target == null) {
45-
if (section.hasParent()) {
45+
if (section.getParent() != null) {
4646
target = section.getParent();
4747
} else {
4848
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void execute(CommandSender sender, String[] args) {
7676
msgr.send("&7Principal: &b{status}",
7777
new Replacement("{status}", section.isPrincipal() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
7878

79-
if (section.hasParent()) {
79+
if (section.getParent() != null) {
8080
TextComponent message = new TextComponent("Parent: ");
8181
message.setColor(ChatColor.GRAY);
8282

@@ -96,13 +96,13 @@ public void execute(CommandSender sender, String[] args) {
9696

9797
msgr.send("&7Provider: &b{name} &7({relation}&7)",
9898
new Replacement("{name}", section.getProvider().name()),
99-
new Replacement("{relation}", section.hasInheritedProvider() ? "Inherited" : "Specified"));
99+
new Replacement("{relation}", section.isInherit() ? "Inherited" : "Specified"));
100100

101101
msgr.send("&7Dummy: &b{status}", new Replacement("{status}", section.isDummy() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
102102

103-
msgr.send("&7Section Server: &b{name}", new Replacement("{name}", section.hasServer() ? section.getServer().getName() : "None"));
103+
msgr.send("&7Section Server: &b{name}", new Replacement("{name}", section.getServer() != null ? section.getServer().getName() : "None"));
104104

105-
if (section.hasCommand()) {
105+
if (section.getCommand() != null) {
106106
msgr.send("&7Section Command: &b{name}&7, Permission: &b{permission}&7, Aliases: &b{aliases}",
107107
new Replacement("{name}", section.getCommand().getName()),
108108
new Replacement("{permission}", section.getCommand().getPermission().equals("") ? "None" : section.getCommand().getPermission()),
@@ -120,8 +120,8 @@ public void execute(CommandSender sender, String[] args) {
120120
StatusInfo status = plugin.getStatusManager().getStatus(server);
121121
msgr.send("&7> Server &b{name} &c({connected}/{maximum}) &7({status}&7)",
122122
new Replacement("{name}", server.getName()),
123-
new Replacement("{connected}", String.valueOf(status.getOnlinePlayers())),
124-
new Replacement("{maximum}", String.valueOf(status.getMaximumPlayers())),
123+
new Replacement("{connected}", String.valueOf(status.getOnline())),
124+
new Replacement("{maximum}", String.valueOf(status.getMaximum())),
125125
new Replacement("{status}", status.isAccessible() ? ChatColor.GREEN + "Accessible" : ChatColor.RED + "Inaccessible")
126126
);
127127
});

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.jaimemartz.lobbybalancer.connection;
22

33
import com.google.common.collect.Iterables;
4+
import lombok.Getter;
45
import me.jaimemartz.lobbybalancer.LobbyBalancer;
56
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
67
import me.jaimemartz.lobbybalancer.ping.StatusInfo;
@@ -57,7 +58,7 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
5758
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
5859
for (ServerInfo server : list) {
5960
StatusInfo status = plugin.getStatusManager().getStatus(server);
60-
if (NetworkManager.getPlayers(server).size() < status.getMaximumPlayers()) {
61+
if (NetworkManager.getPlayers(server).size() < status.getMaximum()) {
6162
return server;
6263
}
6364
}
@@ -76,7 +77,7 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
7677
StatusInfo status = plugin.getStatusManager().getStatus(server);
7778
int count = NetworkManager.getPlayers(server).size();
7879

79-
if (count > max && count <= status.getMaximumPlayers()) {
80+
if (count > max && count <= status.getMaximum()) {
8081
max = count;
8182
target = server;
8283
}
@@ -86,21 +87,13 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
8687
}
8788
};
8889

89-
private final int id;
90-
private final String description;
90+
@Getter private final int id;
91+
@Getter private final String description;
9192

9293
ProviderType(int id, String description) {
9394
this.id = id;
9495
this.description = description;
9596
}
9697

97-
public int getId() {
98-
return id;
99-
}
100-
101-
public String getDescription() {
102-
return description;
103-
}
104-
10598
public abstract ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player);
10699
}

src/main/java/me/jaimemartz/lobbybalancer/ping/StatusInfo.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package me.jaimemartz.lobbybalancer.ping;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
35
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
46
import net.md_5.bungee.api.config.ServerInfo;
57

68
public final class StatusInfo {
7-
private final String description;
8-
private final int online, maximum;
9-
private boolean outdated = true;
9+
@Getter private final String description;
10+
@Getter private final int online, maximum;
11+
@Getter @Setter private boolean outdated = true;
1012

1113
public StatusInfo() {
1214
this("Server Unreachable", 0, 0);
@@ -22,26 +24,6 @@ public StatusInfo(String description, int online, int maximum) {
2224
this.maximum = maximum;
2325
}
2426

25-
public String getDescription() {
26-
return description;
27-
}
28-
29-
public int getOnlinePlayers() {
30-
return online;
31-
}
32-
33-
public int getMaximumPlayers() {
34-
return maximum;
35-
}
36-
37-
public void setOutdated(boolean outdated) {
38-
this.outdated = outdated;
39-
}
40-
41-
public boolean isOutdated() {
42-
return outdated;
43-
}
44-
4527
public boolean isAccessible() {
4628
if (maximum == 0) {
4729
return false;
Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.jaimemartz.lobbybalancer.section;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
35
import me.jaimemartz.lobbybalancer.LobbyBalancer;
46
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
57
import net.md_5.bungee.api.config.ServerInfo;
@@ -13,11 +15,11 @@
1315
import java.util.regex.Pattern;
1416

1517
public class SectionManager {
16-
private ServerSection principal;
1718
private ScheduledTask updateTask;
1819
private final LobbyBalancer plugin;
19-
private final Map<String, ServerSection> sectionStorage = new ConcurrentHashMap<>();
20-
private final Map<ServerInfo, ServerSection> sectionServers = new ConcurrentHashMap<>();
20+
@Getter @Setter private ServerSection principal;
21+
@Getter private final Map<String, ServerSection> sections = new ConcurrentHashMap<>();
22+
@Getter private final Map<ServerInfo, ServerSection> servers = new ConcurrentHashMap<>();
2123

2224
public SectionManager(LobbyBalancer plugin) {
2325
this.plugin = plugin;
@@ -32,27 +34,27 @@ public void load() throws RuntimeException {
3234
plugin.getLogger().info(String.format("Construction of section with name \"%s\"", name));
3335
Configuration section = sections.getSection(name);
3436
ServerSection object = new ServerSection(plugin, name, section);
35-
sectionStorage.put(name, object);
37+
this.sections.put(name, object);
3638
});
3739

38-
sectionStorage.forEach((name, section) -> {
40+
this.sections.forEach((name, section) -> {
3941
plugin.getLogger().info(String.format("Pre-Initialization of section with name \"%s\"", name));
4042
section.preInit();
4143
});
4244

43-
sectionStorage.forEach((name, section) -> {
45+
this.sections.forEach((name, section) -> {
4446
plugin.getLogger().info(String.format("Initialization of section with name \"%s\"", name));
4547
section.load();
4648
});
4749

48-
sectionStorage.forEach((name, section) -> {
50+
this.sections.forEach((name, section) -> {
4951
plugin.getLogger().info(String.format("Post-Initialization of section with name \"%s\"", name));
5052
section.postInit();
5153
});
5254

5355
if (ConfigEntries.SERVERS_UPDATE.get()) {
5456
updateTask = plugin.getProxy().getScheduler().schedule(plugin, () -> {
55-
sectionStorage.forEach((name, section) -> {
57+
this.sections.forEach((name, section) -> {
5658
section.getConfiguration().getStringList("servers").forEach(entry -> {
5759
Pattern pattern = Pattern.compile(entry);
5860
plugin.getProxy().getServers().forEach((key, value) -> {
@@ -71,20 +73,20 @@ public void load() throws RuntimeException {
7173
}
7274

7375
long ending = System.currentTimeMillis() - starting;
74-
plugin.getLogger().info(String.format("A total of %s section(s) have been loaded in %sms", sectionStorage.size(), ending));
76+
plugin.getLogger().info(String.format("A total of %s section(s) have been loaded in %sms", this.sections.size(), ending));
7577
}
7678

7779
public void flush() {
7880
plugin.getLogger().info("Flushing section storage because of plugin shutdown");
79-
sectionStorage.forEach((key, value) -> {
81+
sections.forEach((key, value) -> {
8082
value.setValid(false);
8183

82-
if (value.hasCommand()) {
84+
if (value.getCommand() != null) {
8385
SectionCommand command = value.getCommand();
8486
plugin.getProxy().getPluginManager().unregisterCommand(command);
8587
}
8688

87-
if (value.hasServer()) {
89+
if (value.getServer() != null) {
8890
ServerInfo server = value.getServer();
8991
plugin.getProxy().getServers().remove(server.getName());
9092
}
@@ -95,44 +97,34 @@ public void flush() {
9597
updateTask.cancel();
9698
updateTask = null;
9799
}
98-
sectionStorage.clear();
99-
sectionServers.clear();
100+
sections.clear();
101+
servers.clear();
100102
}
101103

102104
public void register(ServerInfo server, ServerSection section) {
103-
if (sectionServers.containsKey(server)) {
104-
ServerSection other = sectionServers.get(server);
105+
if (servers.containsKey(server)) {
106+
ServerSection other = servers.get(server);
105107
throw new IllegalArgumentException(String.format("The server \"%s\" is already in the section \"%s\"", server.getName(), other.getName()));
106108
}
107109

108110
plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"", server.getName(), section.getName()));
109-
sectionServers.put(server, section);
111+
servers.put(server, section);
110112

111113
}
112114

113115
public ServerSection getByName(String name) {
114-
if (name == null) return null;
115-
return sectionStorage.get(name);
116-
}
117-
118-
public ServerSection getByServer(ServerInfo server) {
119-
if (server == null) return null;
120-
return sectionServers.get(server);
121-
}
122-
123-
public Map<String, ServerSection> getSections() {
124-
return sectionStorage;
125-
}
116+
if (name == null) {
117+
return null;
118+
}
126119

127-
public ServerSection getPrincipal() {
128-
return principal;
120+
return sections.get(name);
129121
}
130122

131-
public void setPrincipal(ServerSection principal) {
132-
this.principal = principal;
133-
}
123+
public ServerSection getByServer(ServerInfo server) {
124+
if (server == null) {
125+
return null;
126+
}
134127

135-
public boolean hasPrincipal() {
136-
return principal != null;
128+
return servers.get(server);
137129
}
138130
}

0 commit comments

Comments
 (0)