mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2025-02-17 04:31:45 +01:00
Commented stuff out, now compiles and I can test things
This commit is contained in:
parent
aba3c161d7
commit
d0863e2ca1
@ -10,11 +10,11 @@
|
||||
- [ ] Add option to force joining a specific section
|
||||
- [x] Add tooltip when you hover over a server in /section info
|
||||
- [ ] Stop using inventivetalent's deprecated bungee-update
|
||||
- [ ] Create a spigot addon that adds connector signs and placeholders
|
||||
- [ ] Separate the types of connections in classes instead of being in ConnectionIntent
|
||||
- [] Create a spigot addon that adds connector signs and placeholders
|
||||
- [x] Separate the types of connections in classes instead of being in ConnectionIntent
|
||||
- [ ] Make the plugin API be not so dependent on a instance of PlayerBalancer
|
||||
- [ ] Separate connection providers in classes instead of being hardcoded in an enum
|
||||
- [ ] Make the feature `marker-descs` work per section
|
||||
- [x] Make the feature `marker-descs` work per section
|
||||
- [ ] Add a identifier to get the servers of a section (auto complete)
|
||||
- [ ] Implement fast connect (dimension change)
|
||||
- [ ] Implement a way to redirect premium players to a section and cracked ones to other section (not sure how this works)
|
||||
|
13
pom.xml
13
pom.xml
@ -68,6 +68,19 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>license-maven-plugin</artifactId>
|
||||
<version>1.13</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>download-licenses</id>
|
||||
<goals>
|
||||
<goal>download-licenses</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
|
@ -1,45 +1,26 @@
|
||||
package com.jaimemartz.playerbalancer;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.injector.Injector;
|
||||
import ch.jalu.injector.InjectorBuilder;
|
||||
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
|
||||
import com.jaimemartz.playerbalancer.commands.MainCommand;
|
||||
import com.jaimemartz.playerbalancer.commands.ManageCommand;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.listener.*;
|
||||
import com.jaimemartz.playerbalancer.manager.PasteHelper;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.ping.StatusManager;
|
||||
import com.jaimemartz.playerbalancer.section.SectionManager;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.SectionHandler;
|
||||
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.types.CheckerProperties;
|
||||
import com.jaimemartz.playerbalancer.settings.types.CommandProperties;
|
||||
import com.jaimemartz.playerbalancer.settings.types.GeneralProperties;
|
||||
import com.jaimemartz.playerbalancer.settings.types.ReconnectorProperties;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.bungeecord.Metrics.SingleLineChart;
|
||||
import org.inventivetalent.update.bungee.BungeeUpdater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PlayerBalancer extends Plugin {
|
||||
@Getter private boolean failed = false;
|
||||
|
||||
//Private instances
|
||||
private Injector injector;
|
||||
private SettingsManager settings;
|
||||
private StatusManager statusManager;
|
||||
private SectionManager sectionManager;
|
||||
private Settings settings;
|
||||
private SectionsHandler handler;
|
||||
|
||||
private Command fallbackCommand, mainCommand, manageCommand;
|
||||
private Listener connectListener, kickListener, messageListener, reloadListener;
|
||||
@ -52,13 +33,16 @@ public class PlayerBalancer extends Plugin {
|
||||
|
||||
injector.register(PlayerBalancer.class, this);
|
||||
injector.register(ProxyServer.class, this.getProxy());
|
||||
injector.registerProvider(SettingsManager.class, SettingsProvider.class);
|
||||
injector.registerProvider(SectionHandler.class, SectionHandlerProvider.class);
|
||||
settings = injector.getSingleton(SettingsManager.class);
|
||||
|
||||
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", () -> sectionManager.getSections().size()));
|
||||
//metrics.addCustomChart(new SingleLineChart("configured_sections", () -> handler.getSections().size()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,6 +50,7 @@ public class PlayerBalancer extends Plugin {
|
||||
mainCommand = new MainCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, mainCommand);
|
||||
|
||||
/*
|
||||
if (settings.getProperty(GeneralProperties.ENABLED)) {
|
||||
if (settings.getProperty(GeneralProperties.SILENT)) {
|
||||
getLogger().setLevel(Level.WARNING);
|
||||
@ -93,7 +78,7 @@ public class PlayerBalancer extends Plugin {
|
||||
}
|
||||
|
||||
if (settings.getProperty(CommandProperties.ENABLED)) {
|
||||
fallbackCommand = injector.newInstance(FallbackCommand.class);
|
||||
fallbackCommand = injector.getSingleton(FallbackCommand.class);
|
||||
getProxy().getPluginManager().registerCommand(this, fallbackCommand);
|
||||
}
|
||||
|
||||
@ -130,6 +115,7 @@ public class PlayerBalancer extends Plugin {
|
||||
getLogger().warning("Nothing is going to work until you do that, you can reload me by using the /balancer command");
|
||||
getLogger().warning("-----------------------------------------------------");
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -142,6 +128,7 @@ public class PlayerBalancer extends Plugin {
|
||||
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;
|
||||
@ -183,6 +170,7 @@ public class PlayerBalancer extends Plugin {
|
||||
|
||||
PlayerLocker.flush();
|
||||
failed = false;
|
||||
*/
|
||||
}
|
||||
|
||||
public boolean reloadPlugin() {
|
||||
|
@ -1,34 +1,23 @@
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.MapBean;
|
||||
import com.jaimemartz.playerbalancer.settings.Settings;
|
||||
import com.jaimemartz.playerbalancer.settings.types.CommandProperties;
|
||||
import com.jaimemartz.playerbalancer.settings.types.GeneralProperties;
|
||||
import com.jaimemartz.playerbalancer.settings.types.MessageProperties;
|
||||
import com.jaimemartz.playerbalancer.settings.types.SectionsHolder;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class FallbackCommand extends Command {
|
||||
@Inject
|
||||
private SettingsManager settings;
|
||||
private Settings settings;
|
||||
|
||||
@Inject
|
||||
private SectionsHolder sections;
|
||||
private SectionsHolder holder;
|
||||
|
||||
@Inject
|
||||
public FallbackCommand(SettingsManager settings) {
|
||||
@Inject //todo maybe make this job of the main class (initializer)
|
||||
public FallbackCommand(Settings settings) {
|
||||
super(
|
||||
settings.getProperty(CommandProperties.COMMAND).getName(),
|
||||
settings.getProperty(CommandProperties.COMMAND).getPermission(),
|
||||
@ -38,11 +27,12 @@ public class FallbackCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
/*
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
Callable<ServerSection> callable = () -> {
|
||||
ServerSection current = sections.getByPlayer(player);
|
||||
ServerSection current = holder.getByPlayer(player);
|
||||
|
||||
if (current != null) {
|
||||
if (settings.getProperty(CommandProperties.IGNORED_SECTIONS).contains(current.getName())) {
|
||||
@ -52,7 +42,7 @@ public class FallbackCommand extends Command {
|
||||
|
||||
MapBean rules = settings.getProperty(CommandProperties.RULES);
|
||||
String bind = rules.getMap().get(current.getName());
|
||||
ServerSection target = sections.getByName(bind);
|
||||
ServerSection target = holder.getByName(bind);
|
||||
|
||||
if (target == null) {
|
||||
if (current.getParent() != null) {
|
||||
@ -73,7 +63,7 @@ public class FallbackCommand extends Command {
|
||||
return target;
|
||||
} else {
|
||||
if (settings.getProperty(GeneralProperties.FALLBACK_PRINCIPAL)) {
|
||||
return sections.getPrincipal();
|
||||
return holder.getPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,15 +77,15 @@ public class FallbackCommand extends Command {
|
||||
try {
|
||||
int number = Integer.parseInt(args[0]);
|
||||
if (number <= 0) {
|
||||
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||
MessageUtils.send(player, settings.getProperty(MessageProperties.INVALID_INPUT));
|
||||
} else if (number > target.getServers().size()) {
|
||||
MessageUtils.send(player, ConfigEntries.FAILURE_MESSAGE.get());
|
||||
MessageUtils.send(player, settings.getProperty(MessageProperties.MISC_FAILURE));
|
||||
} else {
|
||||
ServerInfo server = target.getSortedServers().get(number - 1);
|
||||
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {});
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
|
||||
MessageUtils.send(player, settings.getProperty(MessageProperties.INVALID_INPUT));
|
||||
}
|
||||
} else {
|
||||
ConnectionIntent.simple(plugin, player, target);
|
||||
@ -107,5 +97,6 @@ public class FallbackCommand extends Command {
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,41 @@
|
||||
package com.jaimemartz.playerbalancer.commands;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.ping.ServerStatus;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
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.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ManageCommand extends Command {
|
||||
private final PlayerBalancer plugin;
|
||||
@Inject
|
||||
private PlayerBalancer plugin;
|
||||
|
||||
public ManageCommand(PlayerBalancer plugin) {
|
||||
@Inject
|
||||
private SectionsHandler holder;
|
||||
|
||||
@Inject
|
||||
private StatusManager checker;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
public ManageCommand() {
|
||||
super("section");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
/*
|
||||
if (sender.hasPermission("playerbalancer.admin")) {
|
||||
if (args.length != 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "connect": {
|
||||
if (args.length >= 2) {
|
||||
String input = args[1];
|
||||
ServerSection section = plugin.getSectionManager().getByName(input);
|
||||
ServerSection section = holder.getByName(input);
|
||||
if (section != null) {
|
||||
if (args.length == 3) {
|
||||
ProxiedPlayer player = plugin.getProxy().getPlayer(args[2]);
|
||||
@ -50,7 +52,7 @@ public class ManageCommand extends Command {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MessageUtils.send(sender, ConfigEntries.UNKNOWN_SECTION_MESSAGE.get());
|
||||
MessageUtils.send(sender, settings.getProperty(MessageProperties.UNKNOWN_SECTION));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("Usage: /balancer connect <section> [player]").color(ChatColor.RED).create());
|
||||
@ -61,7 +63,7 @@ public class ManageCommand extends Command {
|
||||
case "info": {
|
||||
if (args.length == 2) {
|
||||
String input = args[1];
|
||||
ServerSection section = plugin.getSectionManager().getByName(input);
|
||||
ServerSection section = holder.getByName(input);
|
||||
if (section != null) {
|
||||
sender.sendMessage(new ComponentBuilder(Strings.repeat("-", 53)).strikethrough(true).color(ChatColor.GRAY).create());
|
||||
|
||||
@ -165,7 +167,7 @@ public class ManageCommand extends Command {
|
||||
);
|
||||
|
||||
section.getServers().forEach(server -> {
|
||||
ServerStatus status = plugin.getStatusManager().getStatus(server);
|
||||
ServerStatus status = checker.getStatus(server);
|
||||
sender.sendMessage(new ComponentBuilder("\u2022 Server: ")
|
||||
.color(ChatColor.GRAY)
|
||||
.append(server.getName())
|
||||
@ -202,7 +204,7 @@ public class ManageCommand extends Command {
|
||||
|
||||
sender.sendMessage(new ComponentBuilder(Strings.repeat("-", 53)).strikethrough(true).color(ChatColor.GRAY).create());
|
||||
} else {
|
||||
MessageUtils.send(sender, ConfigEntries.UNKNOWN_SECTION_MESSAGE.get());
|
||||
MessageUtils.send(sender, settings.getProperty(MessageProperties.UNKNOWN_SECTION));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("Usage: /balancer info <section>").color(ChatColor.RED).create());
|
||||
@ -211,7 +213,7 @@ public class ManageCommand extends Command {
|
||||
}
|
||||
|
||||
case "list": {
|
||||
Map<String, ServerSection> sections = plugin.getSectionManager().getSections();
|
||||
Map<String, ServerSection> sections = sections.getSections();
|
||||
|
||||
if (!sections.isEmpty()) {
|
||||
sender.sendMessage(new ComponentBuilder("These are the registered sections: ").color(ChatColor.GRAY).create());
|
||||
@ -248,5 +250,6 @@ public class ManageCommand extends Command {
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("You do not have permission to execute this command!").color(ChatColor.RED).create());
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,7 @@
|
||||
package com.jaimemartz.playerbalancer.connection;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.ping.ServerStatus;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public abstract class ConnectionIntent {
|
||||
/*
|
||||
protected final PlayerBalancer plugin;
|
||||
protected final ProxiedPlayer player;
|
||||
protected final ServerSection section;
|
||||
@ -122,4 +108,5 @@ public abstract class ConnectionIntent {
|
||||
callback.done(result, throwable);
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
@ -1,16 +1,7 @@
|
||||
package com.jaimemartz.playerbalancer.connection;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.manager.NetworkManager;
|
||||
import com.jaimemartz.playerbalancer.ping.ServerStatus;
|
||||
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) {
|
||||
@ -79,4 +70,5 @@ public enum ProviderType {
|
||||
};
|
||||
|
||||
public abstract ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player);
|
||||
*/
|
||||
}
|
@ -1,21 +1,20 @@
|
||||
package com.jaimemartz.playerbalancer.listener;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import com.jaimemartz.playerbalancer.settings.Settings;
|
||||
import com.jaimemartz.playerbalancer.settings.types.GeneralProperties;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
public class PlayerDisconnectListener implements Listener {
|
||||
private final PlayerBalancer plugin;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public PlayerDisconnectListener(PlayerBalancer plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public class PlayerDisconnectListener implements Listener {
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onDisconnect(PlayerDisconnectEvent event) {
|
||||
@ -23,7 +22,7 @@ public class PlayerDisconnectListener implements Listener {
|
||||
PlayerLocker.unlock(player);
|
||||
|
||||
//Delete this if we want to keep assigned groups even when leaving
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
if (settings.getProperty(GeneralProperties.ASSIGN_TARGETS)) {
|
||||
ServerAssignRegistry.clearAsssignedServers(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
package com.jaimemartz.playerbalancer.listener;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import com.jaimemartz.playerbalancer.settings.Settings;
|
||||
import com.jaimemartz.playerbalancer.settings.types.SectionsHolder;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PluginMessageListener implements Listener {
|
||||
private final PlayerBalancer plugin;
|
||||
@Inject
|
||||
private PlayerBalancer plugin;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@Inject
|
||||
private SectionsHolder holder;
|
||||
|
||||
private final Gson gson;
|
||||
|
||||
public PluginMessageListener(PlayerBalancer plugin) {
|
||||
this.plugin = plugin;
|
||||
public PluginMessageListener() {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.serializeNulls();
|
||||
builder.excludeFieldsWithoutExposeAnnotation();
|
||||
@ -32,6 +32,7 @@ public class PluginMessageListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
/*
|
||||
if (event.getTag().equals("PlayerBalancer") && event.getSender() instanceof Server) {
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||
String request = in.readUTF();
|
||||
@ -40,7 +41,7 @@ public class PluginMessageListener implements Listener {
|
||||
case "Connect": {
|
||||
if (event.getReceiver() instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
ServerSection section = plugin.getSectionManager().getByName(in.readUTF());
|
||||
ServerSection section = holder.getByName(in.readUTF());
|
||||
|
||||
if (section == null) {
|
||||
return;
|
||||
@ -57,7 +58,7 @@ public class PluginMessageListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByName(in.readUTF());
|
||||
ServerSection section = holder.getByName(in.readUTF());
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
@ -70,7 +71,7 @@ public class PluginMessageListener implements Listener {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(stream);
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByName(in.readUTF());
|
||||
ServerSection section = holder.getByName(in.readUTF());
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
@ -95,7 +96,7 @@ public class PluginMessageListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByServer(server);
|
||||
ServerSection section = holder.getByServer(server);
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
@ -112,5 +113,6 @@ public class PluginMessageListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,22 @@
|
||||
package com.jaimemartz.playerbalancer.listener;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import com.jaimemartz.playerbalancer.settings.Settings;
|
||||
import com.jaimemartz.playerbalancer.settings.types.SectionsHolder;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ServerConnectListener implements Listener {
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@Inject
|
||||
private SectionsHolder holder;
|
||||
|
||||
private final PlayerBalancer plugin;
|
||||
|
||||
public ServerConnectListener(PlayerBalancer plugin) {
|
||||
@ -26,11 +25,12 @@ public class ServerConnectListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onConnect(ServerConnectEvent event) {
|
||||
/*
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
ServerInfo target = event.getTarget();
|
||||
|
||||
Callable<ServerSection> callable = () -> {
|
||||
ServerSection section = plugin.getSectionManager().getByServer(target);
|
||||
ServerSection section = holder.getByServer(target);
|
||||
|
||||
if (section != null) {
|
||||
if (PlayerLocker.isLocked(player)) {
|
||||
@ -44,12 +44,12 @@ public class ServerConnectListener implements Listener {
|
||||
}
|
||||
|
||||
if (player.hasPermission("playerbalancer.bypass")) {
|
||||
MessageUtils.send(player, ConfigEntries.BYPASS_MESSAGE.get());
|
||||
MessageUtils.send(player, settings.getProperty(MessageProperties.PLAYER_BYPASS));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (player.getServer() != null && section.getServers().contains(player.getServer().getInfo())) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
if (settings.getProperty(GeneralProperties.ASSIGN_TARGETS)) {
|
||||
ServerAssignRegistry.assignTarget(player, section, target);
|
||||
}
|
||||
return null;
|
||||
@ -66,7 +66,7 @@ public class ServerConnectListener implements Listener {
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void connect(ServerInfo server, Callback<Boolean> callback) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
if (settings.getProperty(GeneralProperties.ASSIGN_TARGETS)) {
|
||||
ServerAssignRegistry.assignTarget(player, section, server);
|
||||
}
|
||||
|
||||
@ -78,5 +78,6 @@ public class ServerConnectListener implements Listener {
|
||||
} catch (Exception e) {
|
||||
//Nothing to do
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,36 @@
|
||||
package com.jaimemartz.playerbalancer.listener;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import com.jaimemartz.playerbalancer.settings.Settings;
|
||||
import com.jaimemartz.playerbalancer.settings.types.SectionsHolder;
|
||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ServerKickListener implements Listener {
|
||||
private final PlayerBalancer plugin;
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
public ServerKickListener(PlayerBalancer plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@Inject
|
||||
private SectionsHolder holder;
|
||||
|
||||
@Inject
|
||||
private PlayerBalancer plugin;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onKick(ServerKickEvent event) {
|
||||
/*
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
ServerInfo from = event.getKickedFrom();
|
||||
|
||||
//Section the player is going to be reconnected
|
||||
Callable<ServerSection> callable = () -> {
|
||||
if (player.getServer() == null) {
|
||||
if (ConfigEntries.RECONNECT_KICK_FORCE_PRINCIPAL.get()) {
|
||||
return plugin.getSectionManager().getPrincipal();
|
||||
if (settings.getProperty(ReconnectorProperties.FORCE_PRINCIPAL)) {
|
||||
return holder.getPrincipal();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -48,51 +40,52 @@ public class ServerKickListener implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByServer(from);
|
||||
ServerSection current = holder.getByServer(from);
|
||||
|
||||
if (section != null) {
|
||||
if ((ConfigEntries.RECONNECT_KICK_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
if (current != null) {
|
||||
if (settings.getProperty(ReconnectorProperties.IGNORED_SECTIONS).contains(current.getName())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
AtomicBoolean matches = new AtomicBoolean(false);
|
||||
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
|
||||
for (String string : ConfigEntries.RECONNECT_KICK_REASONS.get()) {
|
||||
|
||||
for (String string : settings.getProperty(ReconnectorProperties.REASONS)) {
|
||||
if (reason.matches(string) || reason.contains(string)) {
|
||||
matches.set(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_INVERTED.get()) {
|
||||
if (settings.getProperty(ReconnectorProperties.INVERTED)) {
|
||||
matches.set(!matches.get());
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_PRINT_INFO.get()) {
|
||||
if (settings.getProperty(ReconnectorProperties.DEBUG)) {
|
||||
plugin.getLogger().info(String.format("Kick Reason: \"%s\", Found Match: %s", TextComponent.toPlainText(event.getKickReasonComponent()), matches));
|
||||
}
|
||||
|
||||
if (matches.get()) {
|
||||
if (section != null) {
|
||||
Configuration rules = plugin.getConfigHandle().getSection("settings.reconnect-kick.rules");
|
||||
String name = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(name);
|
||||
if (current != null) {
|
||||
MapBean rules = settings.getProperty(CommandProperties.RULES);
|
||||
String bind = rules.getMap().get(current.getName());
|
||||
ServerSection target = holder.getByName(bind);
|
||||
|
||||
if (target == null) {
|
||||
target = section.getParent();
|
||||
target = current.getParent();
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_RESTRICTED.get()) {
|
||||
if (section.getPosition() >= 0 && target.getPosition() < 0) {
|
||||
if (settings.getProperty(ReconnectorProperties.RESTRICTED)) {
|
||||
if (current.getPosition() >= 0 && target.getPosition() < 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
} else {
|
||||
if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) {
|
||||
return plugin.getSectionManager().getPrincipal();
|
||||
if (settings.getProperty(GeneralProperties.FALLBACK_PRINCIPAL)) {
|
||||
return holder.getPrincipal();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,5 +122,6 @@ public class ServerKickListener implements Listener {
|
||||
} catch (Exception e) {
|
||||
//Nothing to do
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,17 +1,14 @@
|
||||
package com.jaimemartz.playerbalancer.manager;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NetworkManager {
|
||||
public static Set<UUID> getPlayers(ServerInfo server) {
|
||||
if (ConfigEntries.REDIS_BUNGEE_ENABLED.get()) {
|
||||
/*
|
||||
if (settings.getProperty(GeneralProperties.REDIS_BUNGEE)) { //TODO false for now
|
||||
try {
|
||||
return RedisBungee.getApi().getPlayersOnServer(server.getName());
|
||||
} catch (Exception e) {
|
||||
@ -20,5 +17,8 @@ public class NetworkManager {
|
||||
}
|
||||
|
||||
return server.getPlayers().stream().map(ProxiedPlayer::getUniqueId).collect(Collectors.toSet());
|
||||
*/
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ public enum PasteHelper {
|
||||
}
|
||||
|
||||
if (url != null) {
|
||||
consumer.accept(sender, url);
|
||||
if (cached) {
|
||||
sender.sendMessage(new ComponentBuilder("This is a cached link, reload the plugin for it to refresh!")
|
||||
.color(ChatColor.RED)
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.jaimemartz.playerbalancer.ping;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import com.jaimemartz.playerbalancer.utils.ServerListPing;
|
||||
import com.jaimemartz.playerbalancer.utils.ServerListPing.StatusResponse;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -14,8 +13,7 @@ public enum PingTactic {
|
||||
ServerListPing utility = new ServerListPing();
|
||||
|
||||
@Override
|
||||
public void ping(ServerInfo server, Callback<ServerStatus> callback, PlayerBalancer plugin) {
|
||||
utility.setTimeout(ConfigEntries.SERVER_CHECK_TIMEOUT.get());
|
||||
public void ping(ServerInfo server, Callback<ServerStatus> callback, Plugin plugin) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
|
||||
try {
|
||||
StatusResponse response = utility.ping(server.getAddress());
|
||||
@ -33,7 +31,7 @@ public enum PingTactic {
|
||||
|
||||
GENERIC {
|
||||
@Override
|
||||
public void ping(ServerInfo server, Callback<ServerStatus> callback, PlayerBalancer plugin) {
|
||||
public void ping(ServerInfo server, Callback<ServerStatus> callback, Plugin plugin) {
|
||||
try {
|
||||
server.ping((ping, throwable) -> {
|
||||
if (ping != null) {
|
||||
@ -53,5 +51,5 @@ public enum PingTactic {
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void ping(ServerInfo server, Callback<ServerStatus> callback, PlayerBalancer plugin);
|
||||
public abstract void ping(ServerInfo server, Callback<ServerStatus> callback, Plugin plugin);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.jaimemartz.playerbalancer.ping;
|
||||
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -30,11 +29,13 @@ public final class ServerStatus {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
for (String pattern : ConfigEntries.SERVER_CHECK_MARKER_DESCS.get()) {
|
||||
if (description.matches(pattern) || description.contains(pattern)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return online < maximum;
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.jaimemartz.playerbalancer.ping;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class StatusManager {
|
||||
private boolean stopped = true;
|
||||
@ -15,6 +12,7 @@ public class StatusManager {
|
||||
private ScheduledTask task;
|
||||
private final Map<ServerInfo, ServerStatus> storage = new HashMap<>();
|
||||
|
||||
/*
|
||||
public void start(PlayerBalancer plugin) {
|
||||
if (task != null) {
|
||||
stop();
|
||||
@ -76,4 +74,5 @@ public class StatusManager {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -1,14 +1,7 @@
|
||||
package com.jaimemartz.playerbalancer.section;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import com.jaimemartz.playerbalancer.utils.MessageUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.List;
|
||||
@ -26,6 +19,7 @@ public class SectionCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
/*
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
//todo share this code with the fallback command instead of having it duplicated
|
||||
@ -54,5 +48,6 @@ public class SectionCommand extends Command {
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,7 @@
|
||||
package com.jaimemartz.playerbalancer.section;
|
||||
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.settings.ConfigEntries;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SectionManager {
|
||||
/*
|
||||
private ScheduledTask updateTask;
|
||||
private final PlayerBalancer plugin;
|
||||
@Getter @Setter private ServerSection principal;
|
||||
@ -150,4 +134,5 @@ public class SectionManager {
|
||||
|
||||
return getByServer(server.getInfo());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -1,27 +1,12 @@
|
||||
package com.jaimemartz.playerbalancer.section;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.jaimemartz.playerbalancer.PlayerBalancer;
|
||||
import com.jaimemartz.playerbalancer.connection.ProviderType;
|
||||
import com.jaimemartz.playerbalancer.utils.AlphanumComparator;
|
||||
import com.jaimemartz.playerbalancer.utils.FixedAdapter;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
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 PlayerBalancer plugin;
|
||||
|
||||
@ -232,4 +217,5 @@ public class ServerSection {
|
||||
if (!valid) return;
|
||||
throw new IllegalStateException("Tried to init a section that is already valid");
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.jaimemartz.playerbalancer.settings;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.migration.MigrationService;
|
||||
import ch.jalu.configme.resource.PropertyResource;
|
||||
|
||||
public class Settings extends SettingsManager {
|
||||
public Settings(PropertyResource resource, MigrationService migrationService, ConfigurationData configurationData) {
|
||||
super(resource, migrationService, configurationData);
|
||||
}
|
||||
}
|
@ -6,14 +6,12 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
public final class CommandBean {
|
||||
private final String name;
|
||||
private final String permission;
|
||||
private final List<String> aliases;
|
||||
private String name;
|
||||
private String permission;
|
||||
private List<String> aliases;
|
||||
|
||||
public CommandBean() {
|
||||
this.name = null;
|
||||
this.permission = null;
|
||||
this.aliases = null;
|
||||
|
||||
}
|
||||
|
||||
public CommandBean(String name, String permission, List<String> aliases) {
|
||||
|
@ -1,14 +0,0 @@
|
||||
package com.jaimemartz.playerbalancer.settings.beans;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SectionHandler {
|
||||
private final Map<String, SectionProperties> sections = new HashMap<>();
|
||||
|
||||
public SectionHandler() {
|
||||
//Default constructor?
|
||||
}
|
||||
|
||||
//TODO The methods in SectionManager
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
package com.jaimemartz.playerbalancer.settings.beans;
|
||||
|
||||
public class SectionProperties {
|
||||
private String name;
|
||||
private boolean dank = true;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,18 @@
|
||||
package com.jaimemartz.playerbalancer.settings.provider;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.SectionHandler;
|
||||
import com.jaimemartz.playerbalancer.settings.types.SectionsHolder;
|
||||
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<SectionHandler> {
|
||||
public class SectionHandlerProvider implements Provider<SectionsHandler> {
|
||||
@Inject
|
||||
private SettingsManager settings;
|
||||
private Settings settings;
|
||||
|
||||
@Override
|
||||
public SectionHandler get() {
|
||||
return settings.getProperty(SectionsHolder.SECTION_HOLDER);
|
||||
public SectionsHandler get() {
|
||||
return new SectionsHandler();
|
||||
//return settings.getProperty(SectionsHolder.MAP);
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
package com.jaimemartz.playerbalancer.settings.provider;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.configurationdata.ConfigurationDataBuilder;
|
||||
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 net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SettingsProvider implements Provider<SettingsManager> {
|
||||
public class SettingsProvider implements Provider<Settings> {
|
||||
@Inject
|
||||
private Plugin plugin;
|
||||
private PlayerBalancer plugin;
|
||||
|
||||
@Override
|
||||
public SettingsManager get() {
|
||||
public Settings get() {
|
||||
plugin.getDataFolder().mkdir();
|
||||
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
@ -40,6 +40,6 @@ public class SettingsProvider implements Provider<SettingsManager> {
|
||||
CommandProperties.class, MessageProperties.class, SectionsHolder.class
|
||||
);
|
||||
|
||||
return new SettingsManager(resource, new PlainMigrationService(), configurationData);
|
||||
return new Settings(resource, new PlainMigrationService(), configurationData);
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,10 @@ public class CheckerProperties implements SettingsHolder {
|
||||
|
||||
public static final Property<Integer> INTERVAL = newProperty("settings.server-check.interval", 10000);
|
||||
|
||||
public static final Property<Integer> TIMEOUT = newProperty("settings.server-check.timeout", 5000);
|
||||
|
||||
public static final Property<List<String>> MARKER_DESCS = newListProperty("settings.server-check.marker-descs",
|
||||
"Sever is not accessible",
|
||||
"Gamemode has already started"
|
||||
);
|
||||
|
||||
public static final Property<Boolean> DEBUG = newProperty("settings.server-check.print-info", false);
|
||||
public static final Property<Boolean> DEBUG = newProperty("settings.server-check.debug", false);
|
||||
}
|
||||
|
@ -2,9 +2,7 @@ package com.jaimemartz.playerbalancer.settings.types;
|
||||
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.CommandBean;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.MapBean;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -14,7 +12,7 @@ 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",
|
||||
public static final Property<CommandBean> COMMAND = newBeanProperty(CommandBean.class, "settings.fallback-command.command",
|
||||
new CommandBean("fallback", "", Arrays.asList("lobby", "hub", "back"))
|
||||
);
|
||||
|
||||
@ -22,7 +20,9 @@ public class CommandProperties implements SettingsHolder {
|
||||
|
||||
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"))
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
@ -2,12 +2,11 @@ package com.jaimemartz.playerbalancer.settings.types;
|
||||
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.MapBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.*;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
public class ReconnectorProperties implements SettingsHolder {
|
||||
public static final Property<Boolean> ENABLED = newProperty("settings.reconnect-kick.enabled", true);
|
||||
@ -22,9 +21,11 @@ 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<Boolean> DEBUG = newProperty("settings.reconnect-kick.debug", false);
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package com.jaimemartz.playerbalancer.settings.types;
|
||||
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.jaimemartz.playerbalancer.settings.beans.SectionHandler;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newBeanProperty;
|
||||
|
||||
public class SectionsHolder implements SettingsHolder {
|
||||
public static final Property<SectionHandler> SECTION_HOLDER = newBeanProperty(SectionHandler.class, "", new SectionHandler());
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user