Skip to content

Commit 21291af

Browse files
committed
Some more progress
1 parent 44a79c0 commit 21291af

File tree

13 files changed

+204
-123
lines changed

13 files changed

+204
-123
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@
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 serverEntries on other sections
8-
- [x] Add a new message for when a player gets connected to a serverName and repurpose the connecting one
97
- [ ] Add support for wildcards, contains, equalsIgnoreCase and regex at the same time
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
12-
- [ ] Stop using inventivetalent's deprecated bungee-update
138
- [ ] Create a spigot addon that adds connector signs and placeholders
14-
- [x] Separate the types of connections in classes instead of being in ConnectionIntent
9+
- [ ] Separate the types of connections in classes instead of being in ConnectionIntent
1510
- [ ] Make the plugin API be not so dependent on a instance of PlayerBalancer
1611
- [ ] Separate connection providers in classes instead of being hardcoded in an enum
1712
- [ ] Make the feature `marker-descs` work per section
18-
- [ ] Add a identifier to get the serverEntries of a section (auto complete)
1913
- [ ] Implement fast connect (dimension change)
2014
- [ ] 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 serverName into a section (duplicated at SectionManager and ServerSection)
22-
- [ ] Unify some of the code used in the FallbackCommand and SectionCommand
15+
- [x] Unify the code that loads serverName into a section (duplicated at SectionManager and ServerSection)
16+
- [x] Unify some of the code used in the FallbackCommand and SectionCommand
2317
- [ ] Make the section initialization work in stages instead of being hardcoded

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

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
import net.md_5.bungee.api.plugin.Command;
1515
import net.md_5.bungee.api.plugin.Listener;
1616
import net.md_5.bungee.api.plugin.Plugin;
17-
import ninja.leaping.configurate.ConfigurationOptions;
1817
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
1918
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
2019
import ninja.leaping.configurate.loader.ConfigurationLoader;
21-
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
22-
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
2320
import org.bstats.bungeecord.Metrics;
2421
import org.inventivetalent.update.bungee.BungeeUpdater;
2522

@@ -32,7 +29,7 @@
3229
public class PlayerBalancer extends Plugin {
3330
private boolean failed = false;
3431
private StatusManager statusManager;
35-
private SettingsHolder mainSettings;
32+
private SettingsHolder settings;
3633
private ConfigurationLoader<CommentedConfigurationNode> loader;
3734
private SectionManager sectionManager;
3835
private NetworkManager networkManager;
@@ -52,36 +49,34 @@ private void enable() {
5249

5350
File file = new File(getDataFolder(), "plugin.conf");
5451

52+
if (!file.exists()) {
53+
try (InputStream in = getResourceAsStream("default.conf")) {
54+
Files.copy(in, file.toPath());
55+
} catch (IOException e) {
56+
e.printStackTrace();
57+
}
58+
}
59+
5560
if (loader == null) {
56-
TypeSerializerCollection serializers = TypeSerializers.getDefaultSerializers().newChild();
57-
ConfigurationOptions options = ConfigurationOptions.defaults().setSerializers(serializers);
58-
loader = HoconConfigurationLoader.builder().setFile(file).setDefaultOptions(options).build();
61+
loader = HoconConfigurationLoader.builder().setFile(file).build();
5962
}
6063

6164
try {
62-
if (!file.exists()) {
63-
try (InputStream in = getResourceAsStream("default.conf")) {
64-
Files.copy(in, file.toPath());
65-
} catch (IOException e) {
66-
e.printStackTrace();
67-
}
68-
}
69-
7065
CommentedConfigurationNode node = loader.load();
71-
mainSettings = node.getValue(TypeToken.of(SettingsHolder.class));
66+
settings = node.getValue(TypeToken.of(SettingsHolder.class));
7267
} catch (Exception e) {
7368
e.printStackTrace();
7469
}
7570

7671
mainCommand = new MainCommand(this);
7772
getProxy().getPluginManager().registerCommand(this, mainCommand);
7873

79-
if (mainSettings.getGeneralProps().isEnabled()) {
80-
if (mainSettings.getGeneralProps().isSilent()) {
74+
if (settings.getGeneralProps().isEnabled()) {
75+
if (settings.getGeneralProps().isSilent()) {
8176
getLogger().setLevel(Level.WARNING);
8277
}
8378

84-
if (mainSettings.getGeneralProps().isAutoReload()) {
79+
if (settings.getGeneralProps().isAutoReload()) {
8580
reloadListener = new ProxyReloadListener(this);
8681
getProxy().getPluginManager().registerListener(this, reloadListener);
8782
}
@@ -99,12 +94,12 @@ private void enable() {
9994
sectionManager.load();
10095

10196
statusManager = new StatusManager(this);
102-
if (mainSettings.getServerCheckerProps().isEnabled()) {
97+
if (settings.getServerCheckerProps().isEnabled()) {
10398
statusManager.start();
10499
}
105100

106-
if (mainSettings.getFallbackCommandProps().isEnabled()) {
107-
fallbackCommand = new FallbackCommand(this, mainSettings.getFallbackCommandProps().getCommand());
101+
if (settings.getFallbackCommandProps().isEnabled()) {
102+
fallbackCommand = new FallbackCommand(this, settings.getFallbackCommandProps().getCommand());
108103
getProxy().getPluginManager().registerCommand(this, fallbackCommand);
109104
}
110105

@@ -123,7 +118,7 @@ private void enable() {
123118

124119
PasteHelper.reset();
125120

126-
if (mainSettings.getKickHandlerProps().isEnabled()) {
121+
if (settings.getKickHandlerProps().isEnabled()) {
127122
kickListener = new ServerKickListener(this);
128123
getProxy().getPluginManager().registerListener(this, kickListener);
129124
}
@@ -151,25 +146,25 @@ private void disable() {
151146
getProxy().getPluginManager().unregisterCommand(mainCommand);
152147
mainCommand = null;
153148

154-
if (mainSettings.getGeneralProps().isEnabled()) {
149+
if (settings.getGeneralProps().isEnabled()) {
155150
//Do not try to do anything if the plugin has not loaded correctly
156151
if (failed) return;
157152

158-
if (mainSettings.getGeneralProps().isAutoReload()) {
153+
if (settings.getGeneralProps().isAutoReload()) {
159154
getProxy().getPluginManager().unregisterListener(reloadListener);
160155
reloadListener = null;
161156
}
162157

163-
if (mainSettings.getServerCheckerProps().isEnabled()) {
158+
if (settings.getServerCheckerProps().isEnabled()) {
164159
statusManager.stop();
165160
}
166161

167-
if (mainSettings.getFallbackCommandProps().isEnabled()) {
162+
if (settings.getFallbackCommandProps().isEnabled()) {
168163
getProxy().getPluginManager().unregisterCommand(fallbackCommand);
169164
fallbackCommand = null;
170165
}
171166

172-
if (mainSettings.getKickHandlerProps().isEnabled()) {
167+
if (settings.getKickHandlerProps().isEnabled()) {
173168
getProxy().getPluginManager().unregisterListener(kickListener);
174169
kickListener = null;
175170
}
@@ -186,7 +181,7 @@ private void disable() {
186181
sectionManager.flush();
187182

188183
/*
189-
if (mainSettings.getGeneralProps().isAssignTargets()) {
184+
if (settings.getGeneralProps().isAssignTargets()) {
190185
ServerAssignRegistry.getTable().clear();
191186
}
192187
*/
@@ -210,7 +205,7 @@ public boolean reloadPlugin() {
210205
}
211206

212207
public SettingsHolder getSettings() {
213-
return mainSettings;
208+
return settings;
214209
}
215210

216211
public SectionManager getSectionManager() {

src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import net.md_5.bungee.api.connection.ProxiedPlayer;
1515
import net.md_5.bungee.api.plugin.Command;
1616

17+
import java.util.ArrayList;
18+
1719
public class FallbackCommand extends Command {
1820
protected final PlayerBalancer plugin;
1921
protected final MessagesProps messages;
@@ -38,10 +40,10 @@ public void execute(CommandSender sender, String[] args) {
3840
int number = Integer.parseInt(args[0]);
3941
if (number <= 0) {
4042
MessageUtils.send(player, messages.getInvalidInputMessage());
41-
} else if (number > target.getMappedServers().size()) {
43+
} else if (number > target.getServers().size()) {
4244
MessageUtils.send(player, messages.getFailureMessage());
4345
} else {
44-
ServerInfo server = target.getSortedServers().get(number - 1);
46+
ServerInfo server = new ArrayList<>(target.getServers()).get(number - 1);
4547
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {
4648
//todo something missing
4749
});

src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public void execute(CommandSender sender, String[] args) {
104104

105105
sender.sendMessage(new ComponentBuilder("Provider: ")
106106
.color(ChatColor.GRAY)
107-
.append(section.getEffectiveProvider().name())
107+
.append(section.getImplicitProvider().name())
108108
.color(ChatColor.AQUA)
109-
.append(String.format(" (%s)", section.isInherited() ? "Inherited" : "Specified"))
109+
.append(String.format(" (%s)", section.isInherited() ? "Implicit" : "Explicit"))
110110
.color(ChatColor.GRAY)
111111
.create()
112112
);
@@ -160,13 +160,13 @@ public void execute(CommandSender sender, String[] args) {
160160
);
161161
}
162162

163-
if (!section.getMappedServers().isEmpty()) {
163+
if (!section.getServers().isEmpty()) {
164164
sender.sendMessage(new ComponentBuilder("Section Servers: ")
165165
.color(ChatColor.GRAY)
166166
.create()
167167
);
168168

169-
section.getMappedServers().forEach(server -> {
169+
section.getServers().forEach(server -> {
170170
ServerStatus status = plugin.getStatusManager().getStatus(server);
171171
sender.sendMessage(new ComponentBuilder("\u2022 Server: ")
172172
.color(ChatColor.GRAY)

src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderTyp
2828
(str) -> str.replace("{section}", section.getName())
2929
);
3030

31-
if (servers == section.getMappedServers()) {
31+
if (servers == section.getServers()) {
3232
throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen");
3333
}
3434

3535
Server current = player.getServer();
3636
if (current != null) {
37-
if (section.getMappedServers().contains(current.getInfo())) {
37+
if (section.getServers().contains(current.getInfo())) {
3838
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getSameSectionMessage());
3939
return;
4040
}
4141
}
4242

43-
if (section.getEffectiveProvider() != ProviderType.NONE) {
43+
if (section.getImplicitProvider() != ProviderType.NONE) {
4444
ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
4545
if (target != null) {
4646
this.connect(target, (response, throwable) -> {
@@ -57,15 +57,15 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderTyp
5757
}
5858

5959
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) {
60-
this(plugin, player, section.getEffectiveProvider(), section);
60+
this(plugin, player, section.getImplicitProvider(), section);
6161
}
6262

6363
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType type, ServerSection section) {
64-
this(plugin, player, type, section, new ArrayList<>(section.getMappedServers()));
64+
this(plugin, player, type, section, new ArrayList<>(section.getServers()));
6565
}
6666

6767
public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
68-
this(plugin, player, section.getEffectiveProvider(), section, servers);
68+
this(plugin, player, section.getImplicitProvider(), section, servers);
6969
}
7070

7171
private ServerInfo fetchServer(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section, ProviderType provider, List<ServerInfo> servers) {

src/main/java/com/jaimemartz/playerbalancer/listener/ServerConnectListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
5151
}
5252

5353
//Checks only for servers (not the section server)
54-
if (section.getMappedServers().contains(target)) {
54+
if (section.getServers().contains(target)) {
5555
if (plugin.getSectionManager().isDummy(section)) {
5656
return null;
5757
}
@@ -61,7 +61,7 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
6161
return null;
6262
}
6363

64-
if (player.getServer() != null && section.getMappedServers().contains(player.getServer().getInfo())) {
64+
if (player.getServer() != null && section.getServers().contains(player.getServer().getInfo())) {
6565
if (plugin.getSectionManager().isReiterative(section)) {
6666
ServerAssignRegistry.assignTarget(player, section, target);
6767
}

src/main/java/com/jaimemartz/playerbalancer/listener/ServerKickListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class ServerKickListener implements Listener {
2424
private final KickHandlerProps props;
25-
private final PlayerBalancer plugin;
2625
private final MessagesProps messages;
26+
private final PlayerBalancer plugin;
2727

2828
public ServerKickListener(PlayerBalancer plugin) {
2929
this.props = plugin.getSettings().getKickHandlerProps();
@@ -64,19 +64,19 @@ public void onKick(ServerKickEvent event) {
6464

6565
if (section != null) {
6666
List<ServerInfo> servers = new ArrayList<>();
67-
servers.addAll(section.getMappedServers());
67+
servers.addAll(section.getServers());
6868
servers.remove(from);
6969

7070
new ConnectionIntent(plugin, player, section, servers) {
7171
@Override
7272
public void connect(ServerInfo server, Callback<Boolean> callback) {
7373
PlayerLocker.lock(player);
74-
MessageUtils.send(player, messages.getKickMessage(), (str) ->
75-
str.replace("{from}", from.getName())
76-
.replace("{to}", server.getName())
77-
.replace("{reason}", event.getKickReason()));
7874
event.setCancelled(true);
7975
event.setCancelServer(server);
76+
MessageUtils.send(player, messages.getKickMessage(), (str) -> str
77+
.replace("{reason}", event.getKickReason())
78+
.replace("{from}", from.getName())
79+
.replace("{to}", server.getName()));
8080
plugin.getProxy().getScheduler().schedule(plugin, () -> {
8181
PlayerLocker.unlock(player);
8282
}, 5, TimeUnit.SECONDS);

src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void start() {
3434
storage.forEach((k, v) -> v.setOutdated(true));
3535

3636
for (ServerSection section : plugin.getSectionManager().getSections().values()) {
37-
for (ServerInfo server : section.getMappedServers()) {
37+
for (ServerInfo server : section.getServers()) {
3838
if (stopped) {
3939
break;
4040
}

0 commit comments

Comments
 (0)