Skip to content

Commit ce9db9e

Browse files
committed
Some progress
1 parent 33ce74f commit ce9db9e

39 files changed

+1513
-932
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
[![Build Status](https://travis-ci.com/Jamezrin/PlayerBalancer.svg?token=2yUi9WpA9QzSbJx9eTmy&branch=master)](https://travis-ci.com/Jamezrin/PlayerBalancer)
55

66
### Things to do:
7-
- [x] Get dummy sections able to have already registered servers on other sections
8-
- [x] Add a new message for when a player gets connected to a server and repurpose the connecting one
7+
- [x] Get dummy sections able to have already registered serverEntries on other sections
8+
- [x] Add a new message for when a player gets connected to a serverName and repurpose the connecting one
99
- [ ] Add support for wildcards, contains, equalsIgnoreCase and regex at the same time
10-
- [ ] Add option to force joining a specific section
11-
- [x] Add tooltip when you hover over a server in /section info
10+
- [ ] Add option to force joining a specific section (to the command)
11+
- [x] Add tooltip when you hover over a serverName in /section info
1212
- [ ] Stop using inventivetalent's deprecated bungee-update
1313
- [ ] Create a spigot addon that adds connector signs and placeholders
1414
- [x] Separate the types of connections in classes instead of being in ConnectionIntent
1515
- [ ] Make the plugin API be not so dependent on a instance of PlayerBalancer
1616
- [ ] Separate connection providers in classes instead of being hardcoded in an enum
17-
- [x] Make the feature `marker-descs` work per section
18-
- [ ] Add a identifier to get the servers of a section (auto complete)
17+
- [ ] Make the feature `marker-descs` work per section
18+
- [ ] Add a identifier to get the serverEntries of a section (auto complete)
1919
- [ ] Implement fast connect (dimension change)
2020
- [ ] Implement a way to redirect premium players to a section and cracked ones to other section (not sure how this works)
21-
- [ ] Unify the code that loads server into a section (duplicated at SectionManager and ServerSection)
21+
- [ ] Unify the code that loads serverName into a section (duplicated at SectionManager and ServerSection)
2222
- [ ] Unify some of the code used in the FallbackCommand and SectionCommand
23-
- [ ] (!) Make the section initialization work in stages instead of being hardcoded
24-
- [ ] (!) Ditch the faucet dependency and use [ConfigMe](https://github.com/AuthMe/ConfigMe) and [DependencyInjector](https://github.com/ljacqu/DependencyInjector) instead
25-
- [ ] Use a separate file for configuring the sections, must be done alongside the previous item
26-
- [ ] Make this repository public
23+
- [ ] Make the section initialization work in stages instead of being hardcoded

pom.xml

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,6 @@
6868
</execution>
6969
</executions>
7070
</plugin>
71-
<!--
72-
<plugin>
73-
<groupId>org.codehaus.mojo</groupId>
74-
<artifactId>license-maven-plugin</artifactId>
75-
<version>1.13</version>
76-
<executions>
77-
<execution>
78-
<id>download-licenses</id>
79-
<goals>
80-
<goal>download-licenses</goal>
81-
</goals>
82-
</execution>
83-
</executions>
84-
</plugin>
85-
-->
8671
</plugins>
8772
<resources>
8873
<resource>
@@ -98,59 +83,30 @@
9883
<version>1.11-SNAPSHOT</version>
9984
<scope>provided</scope>
10085
</dependency>
101-
102-
<dependency>
103-
<groupId>ch.jalu</groupId>
104-
<artifactId>configme</artifactId>
105-
<version>0.6-SNAPSHOT</version>
106-
<scope>compile</scope>
107-
<exclusions>
108-
<!-- This is already shaded in BungeeCord -->
109-
<exclusion>
110-
<groupId>org.yaml</groupId>
111-
<artifactId>snakeyaml</artifactId>
112-
</exclusion>
113-
</exclusions>
114-
</dependency>
115-
116-
<dependency>
117-
<groupId>ch.jalu</groupId>
118-
<artifactId>injector</artifactId>
119-
<version>0.5-SNAPSHOT</version>
120-
<scope>compile</scope>
121-
</dependency>
122-
123-
<!-- TODO Replace with HTTP call to Spigot's API -->
12486
<dependency>
12587
<groupId>org.inventivetalent.update</groupId>
12688
<artifactId>bungee</artifactId>
12789
<version>1.0.1</version>
12890
<scope>compile</scope>
12991
</dependency>
130-
131-
<!-- TODO Replace with our own alternative to "RedisBungee" (maybe) -->
13292
<dependency>
13393
<groupId>com.imaginarycode.minecraft</groupId>
13494
<artifactId>RedisBungee</artifactId>
13595
<version>0.3.8-SNAPSHOT</version>
13696
<scope>provided</scope>
13797
</dependency>
138-
139-
98+
<dependency>
99+
<groupId>ninja.leaping.configurate</groupId>
100+
<artifactId>configurate-hocon</artifactId>
101+
<version>3.3</version>
102+
<scope>compile</scope>
103+
</dependency>
140104
<dependency>
141105
<groupId>org.bstats</groupId>
142106
<artifactId>bstats-bungeecord</artifactId>
143107
<version>1.2</version>
144108
<scope>compile</scope>
145109
</dependency>
146-
147-
<dependency>
148-
<groupId>org.projectlombok</groupId>
149-
<artifactId>lombok</artifactId>
150-
<version>1.16.16</version>
151-
<scope>provided</scope>
152-
</dependency>
153-
154110
<dependency>
155111
<groupId>junit</groupId>
156112
<artifactId>junit</artifactId>
Lines changed: 98 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,91 @@
11
package com.jaimemartz.playerbalancer;
22

3-
import ch.jalu.injector.Injector;
4-
import ch.jalu.injector.InjectorBuilder;
5-
import com.jaimemartz.playerbalancer.settings.Settings;
6-
import com.jaimemartz.playerbalancer.settings.SettingsProvider;
7-
import lombok.Getter;
8-
import net.md_5.bungee.api.ProxyServer;
3+
import com.google.common.reflect.TypeToken;
4+
import com.jaimemartz.playerbalancer.commands.FallbackCommand;
5+
import com.jaimemartz.playerbalancer.commands.MainCommand;
6+
import com.jaimemartz.playerbalancer.commands.ManageCommand;
7+
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
8+
import com.jaimemartz.playerbalancer.listener.*;
9+
import com.jaimemartz.playerbalancer.manager.NetworkManager;
10+
import com.jaimemartz.playerbalancer.manager.PasteHelper;
11+
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
12+
import com.jaimemartz.playerbalancer.ping.StatusManager;
13+
import com.jaimemartz.playerbalancer.section.SectionManager;
14+
import com.jaimemartz.playerbalancer.section.ServerSection;
15+
import com.jaimemartz.playerbalancer.settings.MainSettings;
16+
import com.jaimemartz.playerbalancer.settings.serializers.SectionSerializer;
917
import net.md_5.bungee.api.plugin.Command;
1018
import net.md_5.bungee.api.plugin.Listener;
1119
import net.md_5.bungee.api.plugin.Plugin;
20+
import ninja.leaping.configurate.ConfigurationOptions;
21+
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
22+
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
23+
import ninja.leaping.configurate.loader.ConfigurationLoader;
24+
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
25+
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
1226
import org.bstats.bungeecord.Metrics;
27+
import org.inventivetalent.update.bungee.BungeeUpdater;
1328

14-
public class PlayerBalancer extends Plugin {
15-
@Getter private boolean failed = false;
16-
17-
private Injector injector;
18-
private Settings settings;
29+
import java.io.File;
30+
import java.io.IOException;
31+
import java.util.logging.Level;
1932

33+
public class PlayerBalancer extends Plugin {
34+
private boolean failed = false;
35+
private StatusManager statusManager;
36+
private MainSettings mainSettings;
37+
private ConfigurationLoader<CommentedConfigurationNode> loader;
38+
private SectionManager sectionManager;
39+
private NetworkManager networkManager;
2040
private Command fallbackCommand, mainCommand, manageCommand;
2141
private Listener connectListener, kickListener, messageListener, reloadListener;
2242

2343
@Override
2444
public void onEnable() {
25-
injector = new InjectorBuilder()
26-
.addDefaultHandlers(getClass().getPackage().getName())
27-
.create();
45+
Metrics metrics = new Metrics(this);
46+
metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
47+
48+
this.enable();
49+
}
2850

29-
injector.register(PlayerBalancer.class, this);
30-
injector.register(ProxyServer.class, this.getProxy());
51+
private void enable() {
52+
if (!getDataFolder().exists())
53+
getDataFolder().mkdir();
3154

32-
injector.registerProvider(Settings.class, SettingsProvider.class);
55+
File file = new File(getDataFolder(), "default.conf");
3356

34-
settings = injector.getSingleton(Settings.class);
57+
if (loader == null) {
58+
TypeSerializerCollection serializers = TypeSerializers.getDefaultSerializers().newChild();
59+
serializers.registerType(TypeToken.of(ServerSection.class), new SectionSerializer());
60+
ConfigurationOptions options = ConfigurationOptions.defaults().setSerializers(serializers);
61+
//options.setMapFactory(MapFactories.insertionOrdered());
62+
loader = HoconConfigurationLoader.builder().setFile(file).setDefaultOptions(options).build();
63+
}
3564

36-
Metrics metrics = new Metrics(this);
65+
try {
66+
CommentedConfigurationNode node = loader.load();
3767

38-
if (this.enable()) {
39-
//metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> s.size()));
68+
if (!file.exists()) {
69+
mainSettings = new MainSettings()._defaults();
70+
node.setValue(TypeToken.of(MainSettings.class), mainSettings);
71+
loader.save(node);
72+
} else {
73+
mainSettings = node.getValue(TypeToken.of(MainSettings.class));
74+
}
75+
} catch (Exception e) {
76+
e.printStackTrace();
4077
}
41-
}
4278

43-
private boolean enable() {
44-
/*
4579
mainCommand = new MainCommand(this);
4680
getProxy().getPluginManager().registerCommand(this, mainCommand);
4781

48-
if (settings.getProperty(GeneralProperties.ENABLED)) {
49-
if (settings.getProperty(GeneralProperties.SILENT)) {
82+
if (mainSettings.getGeneralProps().isActive()) {
83+
if (mainSettings.getGeneralProps().isSilent()) {
5084
getLogger().setLevel(Level.WARNING);
5185
}
5286

53-
if (settings.getProperty(GeneralProperties.AUTO_RELOAD)) {
54-
reloadListener = injector.getSingleton(ProxyReloadListener.class);
87+
if (mainSettings.getGeneralProps().isAutoReload()) {
88+
reloadListener = new ProxyReloadListener(this);
5589
getProxy().getPluginManager().registerListener(this, reloadListener);
5690
}
5791

@@ -61,43 +95,43 @@ private boolean enable() {
6195
e.printStackTrace();
6296
}
6397

98+
networkManager = new NetworkManager(this);
6499
sectionManager = new SectionManager(this);
65100

66101
try {
67102
sectionManager.load();
68103

69-
statusManager = new StatusManager();
70-
if (settings.getProperty(CheckerProperties.ENABLED)) {
71-
statusManager.start(this);
104+
statusManager = new StatusManager(this);
105+
if (mainSettings.getServerCheckerProps().isActive()) {
106+
statusManager.start();
72107
}
73108

74-
if (settings.getProperty(CommandProperties.ENABLED)) {
75-
fallbackCommand = injector.getSingleton(FallbackCommand.class);
109+
if (mainSettings.getFallbackCommandProps().isActive()) {
110+
fallbackCommand = new FallbackCommand(this, mainSettings.getFallbackCommandProps().getCommand());
76111
getProxy().getPluginManager().registerCommand(this, fallbackCommand);
77112
}
78113

79-
connectListener = injector.getSingleton(ServerConnectListener.class);
114+
connectListener = new ServerConnectListener(this);
80115
getProxy().getPluginManager().registerListener(this, connectListener);
81116

82-
messageListener = injector.getSingleton(PluginMessageListener.class);
117+
messageListener = new PluginMessageListener(this);
83118
getProxy().getPluginManager().registerListener(this, messageListener);
84119

85-
manageCommand = injector.getSingleton(ManageCommand.class);
120+
manageCommand = new ManageCommand(this);
86121
getProxy().getPluginManager().registerCommand(this, manageCommand);
87122

88-
getProxy().getPluginManager().registerListener(this, injector.getSingleton(PlayerDisconnectListener.class));
123+
getProxy().getPluginManager().registerListener(this, new PlayerDisconnectListener(this));
89124

90125
getProxy().registerChannel("PlayerBalancer");
91126

92-
Stream.of(PasteHelper.values()).forEach(a -> a.setUrl(null));
127+
PasteHelper.reset();
93128

94-
if (settings.getProperty(ReconnectorProperties.ENABLED)) {
95-
kickListener = injector.getSingleton(ServerKickListener.class);
129+
if (mainSettings.getKickHandlerProps().isActive()) {
130+
kickListener = new ServerKickListener(this);
96131
getProxy().getPluginManager().registerListener(this, kickListener);
97132
}
98133

99134
getLogger().info("The plugin has finished loading without any problems");
100-
return true;
101135
} catch (RuntimeException e) {
102136
this.failed = true;
103137
getLogger().severe("The plugin could not continue loading due to an unexpected exception");
@@ -109,8 +143,6 @@ private boolean enable() {
109143
getLogger().warning("Nothing is going to work until you do that, you can reload me by using the /balancer command");
110144
getLogger().warning("-----------------------------------------------------");
111145
}
112-
*/
113-
return false;
114146
}
115147

116148
@Override
@@ -119,24 +151,23 @@ public void onDisable() {
119151
}
120152

121153
private void disable() {
122-
/*
123154
getProxy().getPluginManager().unregisterCommand(mainCommand);
124155
mainCommand = null;
125156

126-
if (settings.getProperty(GeneralProperties.ENABLED)) {
157+
if (mainSettings.getGeneralProps().isActive()) {
127158
//Do not try to do anything if the plugin has not loaded correctly
128-
if (isFailed()) return;
159+
if (failed) return;
129160

130-
if (settings.getProperty(GeneralProperties.AUTO_RELOAD)) {
161+
if (mainSettings.getGeneralProps().isAutoReload()) {
131162
getProxy().getPluginManager().unregisterListener(reloadListener);
132163
reloadListener = null;
133164
}
134165

135-
if (settings.getProperty(CheckerProperties.ENABLED)) {
166+
if (mainSettings.getServerCheckerProps().isActive()) {
136167
statusManager.stop();
137168
}
138169

139-
if (settings.getProperty(CommandProperties.ENABLED)) {
170+
if (mainSettings.getFallbackCommandProps().isActive()) {
140171
getProxy().getPluginManager().unregisterCommand(fallbackCommand);
141172
fallbackCommand = null;
142173
}
@@ -150,34 +181,48 @@ private void disable() {
150181
getProxy().getPluginManager().unregisterCommand(manageCommand);
151182
manageCommand = null;
152183

153-
if (settings.getProperty(ReconnectorProperties.ENABLED)) {
184+
if (mainSettings.getKickHandlerProps().isActive()) {
154185
getProxy().getPluginManager().unregisterListener(kickListener);
155186
kickListener = null;
156187
}
157188

158189
sectionManager.flush();
159190

160-
if (settings.getProperty(GeneralProperties.ASSIGN_TARGETS)) {
191+
if (mainSettings.getGeneralProps().isAssignTargets()) {
161192
ServerAssignRegistry.getTable().clear();
162193
}
163194
}
164195

165196
PlayerLocker.flush();
166197
failed = false;
167-
*/
168198
}
169199

170200
public boolean reloadPlugin() {
171201
getLogger().info("Reloading the plugin...");
172202
long starting = System.currentTimeMillis();
173203

174204
this.disable();
175-
settings.reload();
176205
this.enable();
177206

178207
long ending = System.currentTimeMillis() - starting;
179208
getLogger().info(String.format("The plugin has been reloaded, took %sms", ending));
180209

181210
return !failed;
182211
}
212+
213+
public MainSettings getSettings() {
214+
return mainSettings;
215+
}
216+
217+
public SectionManager getSectionManager() {
218+
return sectionManager;
219+
}
220+
221+
public StatusManager getStatusManager() {
222+
return statusManager;
223+
}
224+
225+
public NetworkManager getNetworkManager() {
226+
return networkManager;
227+
}
183228
}

0 commit comments

Comments
 (0)