Skip to content

Commit 22b3202

Browse files
committed
Previous to stages
1 parent 21291af commit 22b3202

File tree

5 files changed

+112
-22
lines changed

5 files changed

+112
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private void enable() {
6464
try {
6565
CommentedConfigurationNode node = loader.load();
6666
settings = node.getValue(TypeToken.of(SettingsHolder.class));
67+
System.out.println(settings);
6768
} catch (Exception e) {
6869
e.printStackTrace();
6970
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.jaimemartz.playerbalancer.section;
2+
3+
public class SectionLoader {
4+
private final
5+
}

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

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import com.google.common.base.Preconditions;
44
import com.jaimemartz.playerbalancer.PlayerBalancer;
55
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
6+
import com.jaimemartz.playerbalancer.settings.props.shared.SectionProps;
7+
import com.jaimemartz.playerbalancer.utils.FakeServer;
68
import com.jaimemartz.playerbalancer.utils.FixedAdapter;
79
import net.md_5.bungee.api.config.ServerInfo;
810
import net.md_5.bungee.api.connection.ProxiedPlayer;
911
import net.md_5.bungee.api.connection.Server;
1012
import net.md_5.bungee.api.scheduler.ScheduledTask;
1113

12-
import java.net.InetSocketAddress;
1314
import java.util.*;
1415
import java.util.concurrent.atomic.AtomicBoolean;
1516
import java.util.regex.Matcher;
@@ -29,7 +30,7 @@ public SectionManager(PlayerBalancer plugin) {
2930
}
3031

3132
public void load() throws RuntimeException {
32-
plugin.getLogger().info("Loading sections from the config, this may take a while...");
33+
plugin.getLogger().info("Executing section initialization stages, this may take a while...");
3334
long starting = System.currentTimeMillis();
3435

3536
props.getSectionProps().forEach((name, prop) -> {
@@ -119,6 +120,21 @@ public ServerSection getByPlayer(ProxiedPlayer player) {
119120
return getByServer(server.getInfo());
120121
}
121122

123+
private final Stage[] stages = {
124+
new Stage("Creation") {
125+
@Override
126+
public void execute(SectionProps props, ServerSection section) throws RuntimeException {
127+
128+
}
129+
},
130+
new Stage("") {
131+
@Override
132+
public void execute(SectionProps props, ServerSection section) throws RuntimeException {
133+
134+
}
135+
}
136+
};
137+
122138
public void processSection(String sectionName, ServerSection section) throws RuntimeException {
123139
plugin.getLogger().info(String.format("Loading section with name \"%s\"", sectionName));
124140

@@ -143,29 +159,14 @@ public void processSection(String sectionName, ServerSection section) throws Run
143159
Set<ServerInfo> servers = calculateServers(section);
144160
section.getServers().addAll(servers);
145161

146-
//TODO move this to other stage
147-
if (section.getProps().getProvider() != null) {
148-
section.setInherited(false);
149-
} else {
150-
section.setInherited(true);
151-
152-
if (section.getImplicitProvider() != null) {
153-
154-
} else {
155-
throw new IllegalStateException(String.format("The section \"%s\" does not have a provider", sectionName));
156-
}
157-
}
162+
//TODO Load sections
158163

159164
section.setPosition(calculatePosition(section));
160165

161166
Optional.ofNullable(section.getProps().getServerName()).ifPresent(serverName -> {
162-
int port = (int) Math.floor(Math.random() * (0xFFFF + 1)); //Get a random valid port for our fake server
163-
ServerInfo server = plugin.getProxy().constructServerInfo(
164-
"@" + serverName,
165-
new InetSocketAddress("0.0.0.0", port),
166-
String.format("Server of Section %s", sectionName),
167-
false);
167+
FakeServer server = new FakeServer(section);
168168
section.setServer(server);
169+
169170
plugin.getSectionManager().register(server, section);
170171
FixedAdapter.getFakeServers().put(server.getName(), server);
171172
plugin.getProxy().getServers().put(server.getName(), server);
@@ -174,6 +175,7 @@ public void processSection(String sectionName, ServerSection section) throws Run
174175
Optional.ofNullable(section.getProps().getCommand()).ifPresent(props -> {
175176
SectionCommand command = new SectionCommand(plugin, props, section);
176177
section.setCommand(command);
178+
177179
plugin.getProxy().getPluginManager().registerCommand(plugin, command);
178180
});
179181

@@ -258,7 +260,7 @@ public Optional<ServerSection> getBind(Map<String, String> rules, ServerSection
258260
return Optional.ofNullable(res);
259261
}
260262

261-
//maybe store this as a variable?
263+
//todo maybe store this as a variable?
262264
public ServerSection getPrincipal() {
263265
return getByName(props.getPrincipalSectionName());
264266
}
@@ -270,4 +272,21 @@ public boolean isPrincipal(ServerSection section) {
270272
public Map<String, ServerSection> getSections() {
271273
return sections;
272274
}
275+
276+
private abstract static class Stage {
277+
private final String title;
278+
279+
public Stage(String title) {
280+
this.title = title;
281+
}
282+
283+
public String getTitle() {
284+
return title;a
285+
}
286+
287+
public abstract void execute(
288+
SectionProps props,
289+
ServerSection section
290+
) throws RuntimeException;
291+
}
273292
}

src/main/java/com/jaimemartz/playerbalancer/utils/FileInfo.java renamed to src/main/java/com/jaimemartz/playerbalancer/utils/BuildInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.jaimemartz.playerbalancer.utils;
22

3-
public class FileInfo {
3+
public class BuildInfo {
44
public static final String USER_ID = "%%__USER__%%";
55
public static final String RESOURCE_ID = "%%__RESOURCE__%%";
66
public static final String NONCE_ID = "%%__NONCE__%%";
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.jaimemartz.playerbalancer.utils;
2+
3+
import com.jaimemartz.playerbalancer.section.ServerSection;
4+
import net.md_5.bungee.api.Callback;
5+
import net.md_5.bungee.api.CommandSender;
6+
import net.md_5.bungee.api.ServerPing;
7+
import net.md_5.bungee.api.config.ServerInfo;
8+
import net.md_5.bungee.api.connection.ProxiedPlayer;
9+
10+
import java.net.InetSocketAddress;
11+
import java.util.ArrayList;
12+
import java.util.Collection;
13+
import java.util.List;
14+
15+
public class FakeServer implements ServerInfo {
16+
private final ServerSection section;
17+
18+
public FakeServer(ServerSection section) {
19+
this.section = section;
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return "@" + section.getProps().getServerName();
25+
}
26+
27+
@Override
28+
public InetSocketAddress getAddress() {
29+
return null;
30+
}
31+
32+
@Override
33+
public Collection<ProxiedPlayer> getPlayers() {
34+
List<ProxiedPlayer> res = new ArrayList<>();
35+
section.getServers().forEach(server -> {
36+
res.addAll(server.getPlayers());
37+
});
38+
return res;
39+
}
40+
41+
@Override
42+
public String getMotd() {
43+
return "Fake server of section " + section.getName();
44+
}
45+
46+
@Override
47+
public boolean canAccess(CommandSender sender) {
48+
return true;
49+
}
50+
51+
@Override
52+
public void sendData(String channel, byte[] data) {
53+
throw new RuntimeException("Not implemented");
54+
}
55+
56+
@Override
57+
public boolean sendData(String channel, byte[] data, boolean queue) {
58+
throw new RuntimeException("Not implemented");
59+
}
60+
61+
@Override
62+
public void ping(Callback<ServerPing> callback) {
63+
throw new RuntimeException("Not implemented");
64+
}
65+
}

0 commit comments

Comments
 (0)