mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 11:15:30 +01:00
Started using lombok for getters and setters
Will try to use a dependency injector in next commits
This commit is contained in:
parent
1fd5b38499
commit
a6c2470df7
@ -41,5 +41,6 @@
|
||||
<orderEntry type="library" name="Maven: org.bstats:bstats-bungeecord:1.2-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
|
||||
</component>
|
||||
</module>
|
6
pom.xml
6
pom.xml
@ -114,5 +114,11 @@
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -42,7 +42,7 @@ public class FallbackCommand extends Command {
|
||||
ServerSection target = plugin.getSectionManager().getByName(bind);
|
||||
|
||||
if (target == null) {
|
||||
if (section.hasParent()) {
|
||||
if (section.getParent() != null) {
|
||||
target = section.getParent();
|
||||
} else {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
|
@ -76,7 +76,7 @@ public class ManageCommand extends Command {
|
||||
msgr.send("&7Principal: &b{status}",
|
||||
new Replacement("{status}", section.isPrincipal() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
|
||||
|
||||
if (section.hasParent()) {
|
||||
if (section.getParent() != null) {
|
||||
TextComponent message = new TextComponent("Parent: ");
|
||||
message.setColor(ChatColor.GRAY);
|
||||
|
||||
@ -96,13 +96,13 @@ public class ManageCommand extends Command {
|
||||
|
||||
msgr.send("&7Provider: &b{name} &7({relation}&7)",
|
||||
new Replacement("{name}", section.getProvider().name()),
|
||||
new Replacement("{relation}", section.hasInheritedProvider() ? "Inherited" : "Specified"));
|
||||
new Replacement("{relation}", section.isInherit() ? "Inherited" : "Specified"));
|
||||
|
||||
msgr.send("&7Dummy: &b{status}", new Replacement("{status}", section.isDummy() ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
|
||||
|
||||
msgr.send("&7Section Server: &b{name}", new Replacement("{name}", section.hasServer() ? section.getServer().getName() : "None"));
|
||||
msgr.send("&7Section Server: &b{name}", new Replacement("{name}", section.getServer() != null ? section.getServer().getName() : "None"));
|
||||
|
||||
if (section.hasCommand()) {
|
||||
if (section.getCommand() != null) {
|
||||
msgr.send("&7Section Command: &b{name}&7, Permission: &b{permission}&7, Aliases: &b{aliases}",
|
||||
new Replacement("{name}", section.getCommand().getName()),
|
||||
new Replacement("{permission}", section.getCommand().getPermission().equals("") ? "None" : section.getCommand().getPermission()),
|
||||
@ -120,8 +120,8 @@ public class ManageCommand extends Command {
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(server);
|
||||
msgr.send("&7> Server &b{name} &c({connected}/{maximum}) &7({status}&7)",
|
||||
new Replacement("{name}", server.getName()),
|
||||
new Replacement("{connected}", String.valueOf(status.getOnlinePlayers())),
|
||||
new Replacement("{maximum}", String.valueOf(status.getMaximumPlayers())),
|
||||
new Replacement("{connected}", String.valueOf(status.getOnline())),
|
||||
new Replacement("{maximum}", String.valueOf(status.getMaximum())),
|
||||
new Replacement("{status}", status.isAccessible() ? ChatColor.GREEN + "Accessible" : ChatColor.RED + "Inaccessible")
|
||||
);
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.jaimemartz.lobbybalancer.connection;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import lombok.Getter;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
|
||||
import me.jaimemartz.lobbybalancer.ping.StatusInfo;
|
||||
@ -57,7 +58,7 @@ public enum ProviderType {
|
||||
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
for (ServerInfo server : list) {
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(server);
|
||||
if (NetworkManager.getPlayers(server).size() < status.getMaximumPlayers()) {
|
||||
if (NetworkManager.getPlayers(server).size() < status.getMaximum()) {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
@ -76,7 +77,7 @@ public enum ProviderType {
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(server);
|
||||
int count = NetworkManager.getPlayers(server).size();
|
||||
|
||||
if (count > max && count <= status.getMaximumPlayers()) {
|
||||
if (count > max && count <= status.getMaximum()) {
|
||||
max = count;
|
||||
target = server;
|
||||
}
|
||||
@ -86,21 +87,13 @@ public enum ProviderType {
|
||||
}
|
||||
};
|
||||
|
||||
private final int id;
|
||||
private final String description;
|
||||
@Getter private final int id;
|
||||
@Getter private final String description;
|
||||
|
||||
ProviderType(int id, String description) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public abstract ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player);
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
package me.jaimemartz.lobbybalancer.ping;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
public final class StatusInfo {
|
||||
private final String description;
|
||||
private final int online, maximum;
|
||||
private boolean outdated = true;
|
||||
@Getter private final String description;
|
||||
@Getter private final int online, maximum;
|
||||
@Getter @Setter private boolean outdated = true;
|
||||
|
||||
public StatusInfo() {
|
||||
this("Server Unreachable", 0, 0);
|
||||
@ -22,26 +24,6 @@ public final class StatusInfo {
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public int getOnlinePlayers() {
|
||||
return online;
|
||||
}
|
||||
|
||||
public int getMaximumPlayers() {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
public void setOutdated(boolean outdated) {
|
||||
this.outdated = outdated;
|
||||
}
|
||||
|
||||
public boolean isOutdated() {
|
||||
return outdated;
|
||||
}
|
||||
|
||||
public boolean isAccessible() {
|
||||
if (maximum == 0) {
|
||||
return false;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.jaimemartz.lobbybalancer.section;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -13,11 +15,11 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SectionManager {
|
||||
private ServerSection principal;
|
||||
private ScheduledTask updateTask;
|
||||
private final LobbyBalancer plugin;
|
||||
private final Map<String, ServerSection> sectionStorage = new ConcurrentHashMap<>();
|
||||
private final Map<ServerInfo, ServerSection> sectionServers = new ConcurrentHashMap<>();
|
||||
@Getter @Setter private ServerSection principal;
|
||||
@Getter private final Map<String, ServerSection> sections = new ConcurrentHashMap<>();
|
||||
@Getter private final Map<ServerInfo, ServerSection> servers = new ConcurrentHashMap<>();
|
||||
|
||||
public SectionManager(LobbyBalancer plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -32,27 +34,27 @@ public class SectionManager {
|
||||
plugin.getLogger().info(String.format("Construction of section with name \"%s\"", name));
|
||||
Configuration section = sections.getSection(name);
|
||||
ServerSection object = new ServerSection(plugin, name, section);
|
||||
sectionStorage.put(name, object);
|
||||
this.sections.put(name, object);
|
||||
});
|
||||
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
this.sections.forEach((name, section) -> {
|
||||
plugin.getLogger().info(String.format("Pre-Initialization of section with name \"%s\"", name));
|
||||
section.preInit();
|
||||
});
|
||||
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
this.sections.forEach((name, section) -> {
|
||||
plugin.getLogger().info(String.format("Initialization of section with name \"%s\"", name));
|
||||
section.load();
|
||||
});
|
||||
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
this.sections.forEach((name, section) -> {
|
||||
plugin.getLogger().info(String.format("Post-Initialization of section with name \"%s\"", name));
|
||||
section.postInit();
|
||||
});
|
||||
|
||||
if (ConfigEntries.SERVERS_UPDATE.get()) {
|
||||
updateTask = plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
this.sections.forEach((name, section) -> {
|
||||
section.getConfiguration().getStringList("servers").forEach(entry -> {
|
||||
Pattern pattern = Pattern.compile(entry);
|
||||
plugin.getProxy().getServers().forEach((key, value) -> {
|
||||
@ -71,20 +73,20 @@ public class SectionManager {
|
||||
}
|
||||
|
||||
long ending = System.currentTimeMillis() - starting;
|
||||
plugin.getLogger().info(String.format("A total of %s section(s) have been loaded in %sms", sectionStorage.size(), ending));
|
||||
plugin.getLogger().info(String.format("A total of %s section(s) have been loaded in %sms", this.sections.size(), ending));
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
plugin.getLogger().info("Flushing section storage because of plugin shutdown");
|
||||
sectionStorage.forEach((key, value) -> {
|
||||
sections.forEach((key, value) -> {
|
||||
value.setValid(false);
|
||||
|
||||
if (value.hasCommand()) {
|
||||
if (value.getCommand() != null) {
|
||||
SectionCommand command = value.getCommand();
|
||||
plugin.getProxy().getPluginManager().unregisterCommand(command);
|
||||
}
|
||||
|
||||
if (value.hasServer()) {
|
||||
if (value.getServer() != null) {
|
||||
ServerInfo server = value.getServer();
|
||||
plugin.getProxy().getServers().remove(server.getName());
|
||||
}
|
||||
@ -95,44 +97,34 @@ public class SectionManager {
|
||||
updateTask.cancel();
|
||||
updateTask = null;
|
||||
}
|
||||
sectionStorage.clear();
|
||||
sectionServers.clear();
|
||||
sections.clear();
|
||||
servers.clear();
|
||||
}
|
||||
|
||||
public void register(ServerInfo server, ServerSection section) {
|
||||
if (sectionServers.containsKey(server)) {
|
||||
ServerSection other = sectionServers.get(server);
|
||||
if (servers.containsKey(server)) {
|
||||
ServerSection other = servers.get(server);
|
||||
throw new IllegalArgumentException(String.format("The server \"%s\" is already in the section \"%s\"", server.getName(), other.getName()));
|
||||
}
|
||||
|
||||
plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"", server.getName(), section.getName()));
|
||||
sectionServers.put(server, section);
|
||||
servers.put(server, section);
|
||||
|
||||
}
|
||||
|
||||
public ServerSection getByName(String name) {
|
||||
if (name == null) return null;
|
||||
return sectionStorage.get(name);
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sections.get(name);
|
||||
}
|
||||
|
||||
public ServerSection getByServer(ServerInfo server) {
|
||||
if (server == null) return null;
|
||||
return sectionServers.get(server);
|
||||
if (server == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, ServerSection> getSections() {
|
||||
return sectionStorage;
|
||||
}
|
||||
|
||||
public ServerSection getPrincipal() {
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setPrincipal(ServerSection principal) {
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public boolean hasPrincipal() {
|
||||
return principal != null;
|
||||
return servers.get(server);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package me.jaimemartz.lobbybalancer.section;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.connection.ProviderType;
|
||||
import me.jaimemartz.lobbybalancer.utils.AlphanumComparator;
|
||||
@ -16,17 +19,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ServerSection {
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final LobbyBalancer plugin;
|
||||
|
||||
private Configuration configuration;
|
||||
private List<ServerInfo> sortedServers;
|
||||
|
||||
@Expose private final String name;
|
||||
@Expose private boolean principal;
|
||||
@Expose private int position;
|
||||
@Expose private boolean dummy;
|
||||
@Expose private ServerSection parent;
|
||||
@Expose private boolean inherited = false;
|
||||
@Expose private boolean inherit = false;
|
||||
@Expose private List<ServerInfo> servers;
|
||||
@Expose private ProviderType provider;
|
||||
@Expose private ServerInfo server;
|
||||
@ -40,7 +46,7 @@ public class ServerSection {
|
||||
this.servers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ServerSection(LobbyBalancer plugin, String name, boolean principal, int position, boolean dummy, ServerSection parent, boolean inherited, List<ServerInfo> servers, ProviderType provider, ServerInfo server, SectionCommand command, boolean valid) {
|
||||
public ServerSection(LobbyBalancer plugin, String name, boolean principal, int position, boolean dummy, ServerSection parent, boolean inherit, List<ServerInfo> servers, ProviderType provider, ServerInfo server, SectionCommand command, boolean valid) {
|
||||
this.plugin = plugin;
|
||||
this.configuration = null;
|
||||
this.name = name;
|
||||
@ -48,7 +54,7 @@ public class ServerSection {
|
||||
this.position = position;
|
||||
this.dummy = dummy;
|
||||
this.parent = parent;
|
||||
this.inherited = inherited;
|
||||
this.inherit = inherit;
|
||||
this.servers = servers;
|
||||
this.provider = provider;
|
||||
this.server = server;
|
||||
@ -155,9 +161,10 @@ public class ServerSection {
|
||||
}
|
||||
|
||||
//Calculate below principal
|
||||
if (plugin.getSectionManager().hasPrincipal()) {
|
||||
ServerSection principal = plugin.getSectionManager().getPrincipal();
|
||||
if (principal != null) {
|
||||
iterations = 0;
|
||||
current = plugin.getSectionManager().getPrincipal();
|
||||
current = principal;
|
||||
while (current != null) {
|
||||
if (current.equals(this)) {
|
||||
return iterations;
|
||||
@ -187,7 +194,7 @@ public class ServerSection {
|
||||
|
||||
plugin.getLogger().info(String.format("The section \"%s\" inherits the provider from the section \"%s\"", this.name, sect.name));
|
||||
provider = sect.provider;
|
||||
inherited = true;
|
||||
inherit = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,112 +232,4 @@ public class ServerSection {
|
||||
if (!valid) return;
|
||||
throw new IllegalStateException("Tried to init a section that is already valid");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public boolean isPrincipal() {
|
||||
return principal;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public boolean isDummy() {
|
||||
return dummy;
|
||||
}
|
||||
|
||||
public boolean hasParent() {
|
||||
return parent != null;
|
||||
}
|
||||
|
||||
public ServerSection getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public List<ServerInfo> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public List<ServerInfo> getSortedServers() {
|
||||
return sortedServers;
|
||||
}
|
||||
|
||||
public ProviderType getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public boolean hasInheritedProvider() {
|
||||
return inherited;
|
||||
}
|
||||
|
||||
public ServerInfo getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public SectionCommand getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public boolean hasServer() {
|
||||
return server != null;
|
||||
}
|
||||
|
||||
public boolean hasCommand() {
|
||||
return command != null;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void setValid(boolean valid) {
|
||||
this.valid = valid;
|
||||
}
|
||||
|
||||
public void setPrincipal(boolean principal) {
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setDummy(boolean dummy) {
|
||||
this.dummy = dummy;
|
||||
}
|
||||
|
||||
public void setParent(ServerSection parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public void setInherited(boolean inherited) {
|
||||
this.inherited = inherited;
|
||||
}
|
||||
|
||||
public void setServers(List<ServerInfo> servers) {
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
public void setSortedServers(List<ServerInfo> sortedServers) {
|
||||
this.sortedServers = sortedServers;
|
||||
}
|
||||
|
||||
public void setProvider(ProviderType provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public void setServer(ServerInfo server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void setCommand(SectionCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
}
|
@ -63,8 +63,4 @@ public class AdapterWrapper implements ConfigurationAdapter {
|
||||
public Collection<String> getPermissions(String group) {
|
||||
return wrapped.getPermissions(group);
|
||||
}
|
||||
|
||||
public ConfigurationAdapter getWrapped() {
|
||||
return wrapped;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user