Changes to settings structure

This commit is contained in:
Jaime Martinez Rincon 2017-08-16 19:51:27 +02:00
parent d0863e2ca1
commit c877610654
16 changed files with 199 additions and 130 deletions

View File

@ -68,6 +68,7 @@
</execution>
</executions>
</plugin>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
@ -81,6 +82,7 @@
</execution>
</executions>
</plugin>
-->
</plugins>
<resources>
<resource>
@ -100,7 +102,7 @@
<dependency>
<groupId>ch.jalu</groupId>
<artifactId>configme</artifactId>
<version>0.4</version>
<version>0.6-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<!-- This is already shaded in BungeeCord -->
@ -114,7 +116,7 @@
<dependency>
<groupId>ch.jalu</groupId>
<artifactId>injector</artifactId>
<version>0.4</version>
<version>0.5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

View File

@ -2,11 +2,8 @@ package com.jaimemartz.playerbalancer;
import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder;
import com.jaimemartz.playerbalancer.commands.MainCommand;
import com.jaimemartz.playerbalancer.settings.Settings;
import com.jaimemartz.playerbalancer.settings.beans.SectionsHandler;
import com.jaimemartz.playerbalancer.settings.provider.SectionHandlerProvider;
import com.jaimemartz.playerbalancer.settings.provider.SettingsProvider;
import com.jaimemartz.playerbalancer.settings.SettingsProvider;
import lombok.Getter;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Command;
@ -20,7 +17,6 @@ public class PlayerBalancer extends Plugin {
//Private instances
private Injector injector;
private Settings settings;
private SectionsHandler handler;
private Command fallbackCommand, mainCommand, manageCommand;
private Listener connectListener, kickListener, messageListener, reloadListener;
@ -35,29 +31,28 @@ public class PlayerBalancer extends Plugin {
injector.register(ProxyServer.class, this.getProxy());
injector.registerProvider(Settings.class, SettingsProvider.class);
injector.registerProvider(SectionsHandler.class, SectionHandlerProvider.class);
settings = injector.getSingleton(Settings.class);
handler = injector.getSingleton(SectionsHandler.class);
Metrics metrics = new Metrics(this);
if (this.enable()) {
//metrics.addCustomChart(new SingleLineChart("configured_sections", () -> handler.getSections().size()));
//metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> s.size()));
}
}
private boolean enable() {
/*
mainCommand = new MainCommand(this);
getProxy().getPluginManager().registerCommand(this, mainCommand);
/*
if (settings.getProperty(GeneralProperties.ENABLED)) {
if (settings.getProperty(GeneralProperties.SILENT)) {
getLogger().setLevel(Level.WARNING);
}
if (settings.getProperty(GeneralProperties.AUTO_RELOAD)) {
reloadListener = new ProxyReloadListener(this);
reloadListener = injector.getSingleton(ProxyReloadListener.class);
getProxy().getPluginManager().registerListener(this, reloadListener);
}
@ -82,23 +77,23 @@ public class PlayerBalancer extends Plugin {
getProxy().getPluginManager().registerCommand(this, fallbackCommand);
}
connectListener = new ServerConnectListener(this);
connectListener = injector.getSingleton(ServerConnectListener.class);
getProxy().getPluginManager().registerListener(this, connectListener);
messageListener = new PluginMessageListener(this);
messageListener = injector.getSingleton(PluginMessageListener.class);
getProxy().getPluginManager().registerListener(this, messageListener);
manageCommand = new ManageCommand(this);
manageCommand = injector.getSingleton(ManageCommand.class);
getProxy().getPluginManager().registerCommand(this, manageCommand);
getProxy().getPluginManager().registerListener(this, new PlayerDisconnectListener(this));
getProxy().getPluginManager().registerListener(this, injector.getSingleton(PlayerDisconnectListener.class));
getProxy().registerChannel("PlayerBalancer");
Stream.of(PasteHelper.values()).forEach(a -> a.setUrl(null));
if (settings.getProperty(ReconnectorProperties.ENABLED)) {
kickListener = new ServerKickListener(this);
kickListener = injector.getSingleton(ServerKickListener.class);
getProxy().getPluginManager().registerListener(this, kickListener);
}
@ -125,10 +120,10 @@ public class PlayerBalancer extends Plugin {
}
private void disable() {
/*
getProxy().getPluginManager().unregisterCommand(mainCommand);
mainCommand = null;
/*
if (settings.getProperty(GeneralProperties.ENABLED)) {
//Do not try to do anything if the plugin has not loaded correctly
if (isFailed()) return;

View File

@ -1,6 +1,5 @@
package com.jaimemartz.playerbalancer.commands;
import com.google.common.collect.Iterables;
import com.jaimemartz.playerbalancer.settings.Settings;
import com.jaimemartz.playerbalancer.settings.types.CommandProperties;
import com.jaimemartz.playerbalancer.settings.types.SectionsHolder;
@ -21,7 +20,7 @@ public class FallbackCommand extends Command {
super(
settings.getProperty(CommandProperties.COMMAND).getName(),
settings.getProperty(CommandProperties.COMMAND).getPermission(),
Iterables.toArray(settings.getProperty(CommandProperties.COMMAND).getAliases(), String.class)
settings.getProperty(CommandProperties.COMMAND).getAliases()
);
}

View File

@ -3,7 +3,6 @@ package com.jaimemartz.playerbalancer.commands;
import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.ping.StatusManager;
import com.jaimemartz.playerbalancer.settings.Settings;
import com.jaimemartz.playerbalancer.settings.beans.SectionsHandler;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
@ -13,9 +12,6 @@ public class ManageCommand extends Command {
@Inject
private PlayerBalancer plugin;
@Inject
private SectionsHandler holder;
@Inject
private StatusManager checker;

View File

@ -1,7 +1,15 @@
package com.jaimemartz.playerbalancer.connection;
import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.manager.NetworkManager;
import com.jaimemartz.playerbalancer.section.ServerSection;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public enum ProviderType {
/*
NONE {
@Override
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
@ -38,6 +46,7 @@ public enum ProviderType {
PROGRESSIVE {
@Override
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
/*
for (ServerInfo server : list) {
ServerStatus status = plugin.getStatusManager().getStatus(server);
if (NetworkManager.getPlayers(server).size() < status.getMaximum()) {
@ -46,12 +55,15 @@ public enum ProviderType {
}
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
*/
return null;
}
},
FILLER {
@Override
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
/*
int max = Integer.MIN_VALUE;
ServerInfo target = null;
@ -66,9 +78,10 @@ public enum ProviderType {
}
return target;
*/
return null;
}
};
public abstract ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player);
*/
}

View File

@ -1,4 +1,4 @@
package com.jaimemartz.playerbalancer.settings.provider;
package com.jaimemartz.playerbalancer.settings;
import ch.jalu.configme.configurationdata.ConfigurationData;
import ch.jalu.configme.configurationdata.ConfigurationDataBuilder;
@ -6,7 +6,6 @@ import ch.jalu.configme.migration.PlainMigrationService;
import ch.jalu.configme.resource.PropertyResource;
import ch.jalu.configme.resource.YamlFileResource;
import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.settings.Settings;
import com.jaimemartz.playerbalancer.settings.types.*;
import javax.inject.Inject;

View File

@ -1,22 +0,0 @@
package com.jaimemartz.playerbalancer.settings.beans;
import lombok.Data;
import java.util.List;
@Data
public final class CommandBean {
private String name;
private String permission;
private List<String> aliases;
public CommandBean() {
}
public CommandBean(String name, String permission, List<String> aliases) {
this.name = name;
this.permission = permission;
this.aliases = aliases;
}
}

View File

@ -0,0 +1,41 @@
package com.jaimemartz.playerbalancer.settings.beans;
public final class CommandData {
private String name;
private String permission;
private String[] aliases;
public CommandData() {
}
public CommandData(String name, String permission, String... aliases) {
this.name = name;
this.permission = permission;
this.aliases = aliases;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPermission() {
return permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public String[] getAliases() {
return aliases;
}
public void setAliases(String[] aliases) {
this.aliases = aliases;
}
}

View File

@ -1,21 +0,0 @@
package com.jaimemartz.playerbalancer.settings.beans;
import java.util.HashMap;
import java.util.Map;
public final class MapBean {
private final Map<String, String> map;
public MapBean() {
this.map = null;
}
public MapBean(Map<String, String> defaults) {
this.map = new HashMap<>();
map.putAll(defaults);
}
public Map<String, String> getMap() {
return map;
}
}

View File

@ -0,0 +1,71 @@
package com.jaimemartz.playerbalancer.settings.beans;
import com.jaimemartz.playerbalancer.connection.ProviderType;
import java.util.List;
public class SectionData {
private Boolean principal = true;
private Boolean dummy;
private String parent;
private List<String> servers;
private ProviderType provider;
private CommandData command;
private String server;
public Boolean isPrincipal() {
return principal;
}
public void setPrincipal(boolean principal) {
this.principal = principal;
}
public Boolean isDummy() {
return dummy;
}
public void setDummy(boolean dummy) {
this.dummy = dummy;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public List<String> getServers() {
return servers;
}
public void setServers(List<String> servers) {
this.servers = servers;
}
public ProviderType getProvider() {
return provider;
}
public void setProvider(ProviderType provider) {
this.provider = provider;
}
public CommandData getCommand() {
return command;
}
public void setCommand(CommandData command) {
this.command = command;
}
public String getServer() {
return server;
}
public void setServer(String server) {
this.server = server;
}
}

View File

@ -1,6 +0,0 @@
package com.jaimemartz.playerbalancer.settings.beans;
public class SectionProperties {
private String name;
private boolean dank = true;
}

View File

@ -1,21 +0,0 @@
package com.jaimemartz.playerbalancer.settings.beans;
import java.util.HashMap;
import java.util.Map;
public class SectionsHandler {
public Map<String, SectionProperties> sections;
public SectionsHandler() {
}
public SectionsHandler(boolean defaults) {
if (defaults) {
sections = new HashMap<>();
sections.put("test", new SectionProperties());
sections.put("test31", new SectionProperties());
sections.put("test321", new SectionProperties());
}
}
}

View File

@ -1,18 +0,0 @@
package com.jaimemartz.playerbalancer.settings.provider;
import com.jaimemartz.playerbalancer.settings.Settings;
import com.jaimemartz.playerbalancer.settings.beans.SectionsHandler;
import javax.inject.Inject;
import javax.inject.Provider;
public class SectionHandlerProvider implements Provider<SectionsHandler> {
@Inject
private Settings settings;
@Override
public SectionsHandler get() {
return new SectionsHandler();
//return settings.getProperty(SectionsHolder.MAP);
}
}

View File

@ -2,27 +2,26 @@ package com.jaimemartz.playerbalancer.settings.types;
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.properties.Property;
import com.jaimemartz.playerbalancer.settings.beans.CommandBean;
import com.google.common.collect.ImmutableMap;
import com.jaimemartz.playerbalancer.settings.beans.CommandData;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static ch.jalu.configme.properties.PropertyInitializer.*;
public class CommandProperties implements SettingsHolder {
public static final Property<Boolean> ENABLED = newProperty("settings.fallback-command.enabled", true);
public static final Property<CommandBean> COMMAND = newBeanProperty(CommandBean.class, "settings.fallback-command.command",
new CommandBean("fallback", "", Arrays.asList("lobby", "hub", "back"))
public static final Property<CommandData> COMMAND = newBeanProperty(CommandData.class, "settings.fallback-command.command",
new CommandData("fallback", "", "lobby", "hub", "back")
);
public static final Property<List<String>> IGNORED_SECTIONS = newListProperty("settings.fallback-command.ignored");
public static final Property<Boolean> RESTRICTED = newProperty("settings.fallback-command.restricted", true);
/*
public static final Property<MapBean> RULES = newBeanProperty(MapBean.class, "settings.reconnect-kick",
new MapBean(ImmutableMap.of("section-from", "section-to"))
public static final Property<Map<String, String>> RULES = newStringKeyMapProperty(String.class, "settings.fallback-command.rules",
ImmutableMap.of("section-from", "section-to")
);
*/
}

View File

@ -3,10 +3,11 @@ package com.jaimemartz.playerbalancer.settings.types;
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.properties.Property;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
import static ch.jalu.configme.properties.PropertyInitializer.*;
public class ReconnectorProperties implements SettingsHolder {
public static final Property<Boolean> ENABLED = newProperty("settings.reconnect-kick.enabled", true);
@ -21,11 +22,9 @@ public class ReconnectorProperties implements SettingsHolder {
public static final Property<Boolean> FORCE_PRINCIPAL = newProperty("settings.reconnect-kick.force-principal", false);
/*
public static final Property<MapBean> RULES = newBeanProperty(MapBean.class, "settings.reconnect-kick",
new MapBean(ImmutableMap.of("section-from", "section-to"))
public static final Property<Map<String, String>> RULES = newStringKeyMapProperty(String.class, "settings.reconnect-kick.rules",
Collections.emptyMap()//ImmutableMap.of("section-from", "section-to")
);
*/
public static final Property<Boolean> DEBUG = newProperty("settings.reconnect-kick.debug", false);
}

View File

@ -1,7 +1,50 @@
package com.jaimemartz.playerbalancer.settings.types;
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.properties.Property;
import com.jaimemartz.playerbalancer.connection.ProviderType;
import com.jaimemartz.playerbalancer.settings.beans.CommandData;
import com.jaimemartz.playerbalancer.settings.beans.SectionData;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static ch.jalu.configme.properties.PropertyInitializer.newStringKeyMapProperty;
public class SectionsHolder implements SettingsHolder {
public static final Property<Map<String, SectionData>> SECTIONS = newStringKeyMapProperty(SectionData.class, "sections", getDefaultSections());
public static Map<String, SectionData> getDefaultSections() {
Map<String, SectionData> map = new HashMap<>();
SectionData authLobbies = new SectionData();
authLobbies.setProvider(ProviderType.RANDOM);
authLobbies.setServers(Arrays.asList("Auth1", "Auth2", "Auth3"));
map.put("auth-lobbies", authLobbies);
SectionData generalLobbies = new SectionData();
generalLobbies.setParent("auth-lobbies");
generalLobbies.setPrincipal(true);
generalLobbies.setProvider(ProviderType.RANDOM);
generalLobbies.setServers(Arrays.asList("SWLobby1", "SWLobby2", "SWLobby3"));
map.put("general-lobbies", generalLobbies);
SectionData skywarsLobbies = new SectionData();
skywarsLobbies.setParent("general-lobbies");
skywarsLobbies.setProvider(ProviderType.LOWEST);
skywarsLobbies.setServers(Arrays.asList("SWLobby1", "SWLobby2", "SWLobby3"));
map.put("skywars-lobbies", skywarsLobbies);
SectionData skywarsGames = new SectionData();
skywarsGames.setProvider(ProviderType.FILLER);
skywarsGames.setParent("skywarsd-lobbies");
skywarsGames.setServers(Arrays.asList("SW_1", "SW2", "SW3", "SW4", "SW5"));
skywarsGames.setCommand(new CommandData("playskywars", "", "skywars"));
skywarsGames.setServer("skywars");
skywarsGames.setDummy(true);
map.put("skywars-games", skywarsGames);
return map;
}
}