Skip to content

Commit 62ebd71

Browse files
committed
Some more little changes
1 parent 3d293b1 commit 62ebd71

File tree

4 files changed

+28
-51
lines changed

4 files changed

+28
-51
lines changed

src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
2020
import ninja.leaping.configurate.loader.ConfigurationLoader;
2121
import org.bstats.bungeecord.Metrics;
22+
import org.bstats.bungeecord.Metrics.SingleLineChart;
2223
import org.inventivetalent.update.bungee.BungeeUpdater;
2324

2425
import java.io.File;
@@ -31,19 +32,24 @@ public class PlayerBalancer extends Plugin {
3132
private boolean failed = false;
3233
private StatusManager statusManager;
3334
private SettingsHolder settings;
34-
private ConfigurationLoader<CommentedConfigurationNode> loader;
3535
private SectionManager sectionManager;
3636
private NetworkManager networkManager;
37+
private ConfigurationLoader<CommentedConfigurationNode> loader;
3738
private Command fallbackCommand, mainCommand, manageCommand;
3839
private Listener connectListener, kickListener, messageListener, reloadListener;
3940

4041
@Override
4142
public void onEnable() {
4243
Metrics metrics = new Metrics(this);
43-
metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
44+
metrics.addCustomChart(new SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
4445
this.enable();
4546
}
4647

48+
@Override
49+
public void onDisable() {
50+
disable();
51+
}
52+
4753
private void enable() {
4854
if (!getDataFolder().exists())
4955
getDataFolder().mkdir();
@@ -65,7 +71,6 @@ private void enable() {
6571
try {
6672
CommentedConfigurationNode node = loader.load();
6773
settings = node.getValue(TypeToken.of(SettingsHolder.class));
68-
System.out.println(settings);
6974
} catch (Exception e) {
7075
e.printStackTrace();
7176
}
@@ -139,11 +144,6 @@ private void enable() {
139144
}
140145
}
141146

142-
@Override
143-
public void onDisable() {
144-
disable();
145-
}
146-
147147
private void disable() {
148148
getProxy().getPluginManager().unregisterCommand(mainCommand);
149149
mainCommand = null;

src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.md_5.bungee.api.config.ServerInfo;
99
import net.md_5.bungee.api.connection.ProxiedPlayer;
1010
import net.md_5.bungee.api.connection.Server;
11-
import net.md_5.bungee.api.scheduler.ScheduledTask;
1211

1312
import java.util.*;
1413
import java.util.concurrent.atomic.AtomicBoolean;
@@ -18,7 +17,6 @@
1817
public class SectionManager {
1918
private final PlayerBalancer plugin;
2019
private final BalancerProps props;
21-
private ScheduledTask updateTask;
2220
private ServerSection principal;
2321

2422
private final Map<String, ServerSection> sections = Collections.synchronizedMap(new HashMap<>());
@@ -64,11 +62,6 @@ public void flush() {
6462
}
6563
});
6664

67-
if (updateTask != null) {
68-
updateTask.cancel();
69-
updateTask = null;
70-
}
71-
7265
principal = null;
7366
sections.clear();
7467
servers.clear();
@@ -122,9 +115,9 @@ public ServerSection getByPlayer(ProxiedPlayer player) {
122115
private final Stage[] stages = {
123116
new SectionStage("Constructing sections") {
124117
@Override
125-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
126-
ServerSection object = new ServerSection(name, props);
127-
sections.put(name, object);
118+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
119+
ServerSection object = new ServerSection(sectionName, sectionProps);
120+
sections.put(sectionName, object);
128121
}
129122
},
130123
new GlobalStage("Processing principal section") {
@@ -141,9 +134,9 @@ public void execute() {
141134
},
142135
new SectionStage("Processing parents") {
143136
@Override
144-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
145-
if (props.getParentName() != null) {
146-
ServerSection parent = getByName(props.getParentName());
137+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
138+
if (sectionProps.getParentName() != null) {
139+
ServerSection parent = getByName(sectionProps.getParentName());
147140
if (principal.equals(section) && parent == null) {
148141
throw new IllegalArgumentException(String.format(
149142
"The section \"%s\" has an invalid parent set",
@@ -157,7 +150,7 @@ public void execute(String name, SectionProps props, ServerSection section) thro
157150
},
158151
new SectionStage("Validating parents") {
159152
@Override
160-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
153+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
161154
ServerSection parent = section.getParent();
162155
if (parent != null && parent.getParent() == section) {
163156
throw new IllegalStateException(String.format(
@@ -170,8 +163,8 @@ public void execute(String name, SectionProps props, ServerSection section) thro
170163
},
171164
new SectionStage("Validating providers") {
172165
@Override
173-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
174-
if (props.getProvider() == null) {
166+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
167+
if (sectionProps.getProvider() == null) {
175168
ServerSection current = section.getParent();
176169
if (current != null) {
177170
while (current.getExplicitProvider() == null) {
@@ -193,20 +186,20 @@ public void execute(String name, SectionProps props, ServerSection section) thro
193186
},
194187
new SectionStage("Calculating positions") {
195188
@Override
196-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
189+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
197190
section.setPosition(calculatePosition(section));
198191
}
199192
},
200193
new SectionStage("Resolving servers") {
201194
@Override
202-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
195+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
203196
section.setServers(calculateServers(section));
204197
}
205198
},
206199
new SectionStage("Section server processing") {
207200
@Override
208-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
209-
if (props.getServerName() != null) {
201+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
202+
if (sectionProps.getServerName() != null) {
210203
FakeServer server = new FakeServer(section);
211204
section.setServer(server);
212205
plugin.getSectionManager().register(server, section);
@@ -217,20 +210,20 @@ public void execute(String name, SectionProps props, ServerSection section) thro
217210
},
218211
new SectionStage("Section command processing") {
219212
@Override
220-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
221-
if (props.getCommand() != null) {
222-
SectionCommand command = new SectionCommand(plugin, props.getCommand(), section);
213+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
214+
if (sectionProps.getCommand() != null) {
215+
SectionCommand command = new SectionCommand(plugin, sectionProps.getCommand(), section);
223216
section.setCommand(command);
224217
plugin.getProxy().getPluginManager().registerCommand(plugin, command);
225218
}
226219
}
227220
},
228221
new SectionStage("Finishing loading sections") {
229222
@Override
230-
public void execute(String name, SectionProps props, ServerSection section) throws RuntimeException {
223+
public void execute(String sectionName, SectionProps sectionProps, ServerSection section) throws RuntimeException {
231224
section.setValid(true);
232225
}
233-
}
226+
},
234227
};
235228

236229
public Set<ServerInfo> calculateServers(ServerSection section) {
@@ -345,8 +338,8 @@ private SectionStage(String title) {
345338
}
346339

347340
public abstract void execute(
348-
String name,
349-
SectionProps props,
341+
String sectionName,
342+
SectionProps sectionProps,
350343
ServerSection section
351344
) throws RuntimeException;
352345
}

src/main/java/com/jaimemartz/playerbalancer/settings/props/GeneralProps.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public class GeneralProps {
2020
@Setting(value = "fallback-principal")
2121
private boolean fallbackPrincipal;
2222

23-
@Setting(value = "auto-refresh")
24-
private boolean autoRefresh;
25-
2623
public boolean isEnabled() {
2724
return enabled;
2825
}
@@ -63,14 +60,6 @@ public void setFallbackPrincipal(boolean fallbackPrincipal) {
6360
this.fallbackPrincipal = fallbackPrincipal;
6461
}
6562

66-
public boolean isAutoRefresh() {
67-
return autoRefresh;
68-
}
69-
70-
public void setAutoRefresh(boolean autoRefresh) {
71-
this.autoRefresh = autoRefresh;
72-
}
73-
7463
@Override
7564
public String toString() {
7665
return "GeneralProps{" +
@@ -79,7 +68,6 @@ public String toString() {
7968
", autoReload=" + autoReload +
8069
", redisBungee=" + redisBungee +
8170
", fallbackPrincipal=" + fallbackPrincipal +
82-
", autoRefresh=" + autoRefresh +
8371
'}';
8472
}
8573
}

src/main/resources/default.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ general {
88
# IMPORTANT! Set this to true after configuring the plugin!
99
enabled=false
1010

11-
# When true, the plugin will check for new servers added to bungee
12-
# TODO Not done yet
13-
auto-refresh=false
14-
1511
# When true, the plugin will reload when you execute /greload
1612
auto-reload=true
1713

0 commit comments

Comments
 (0)