Skip to content

Commit 5fadacb

Browse files
committed
Some more changes
1 parent e707d82 commit 5fadacb

File tree

12 files changed

+116
-84
lines changed

12 files changed

+116
-84
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</repository>
2525
<repository>
2626
<id>inventive-repo</id>
27-
<url>http://repo.inventivetalent.org/content/groups/public/</url>
27+
<url>https://repo.inventivetalent.org/content/groups/public/</url>
2828
</repository>
2929
<repository>
3030
<id>xephi-repo</id>

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import java.io.File;
2727
import java.io.IOException;
28+
import java.io.InputStream;
29+
import java.nio.file.Files;
2830
import java.util.logging.Level;
2931

3032
public class PlayerBalancer extends Plugin {
@@ -41,7 +43,6 @@ public class PlayerBalancer extends Plugin {
4143
public void onEnable() {
4244
Metrics metrics = new Metrics(this);
4345
metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
44-
4546
this.enable();
4647
}
4748

@@ -53,21 +54,21 @@ private void enable() {
5354

5455
if (loader == null) {
5556
TypeSerializerCollection serializers = TypeSerializers.getDefaultSerializers().newChild();
56-
//serializers.registerType(TypeToken.of(ServerSection.class), new SectionSerializer());
5757
ConfigurationOptions options = ConfigurationOptions.defaults().setSerializers(serializers);
5858
loader = HoconConfigurationLoader.builder().setFile(file).setDefaultOptions(options).build();
5959
}
6060

6161
try {
62-
CommentedConfigurationNode node = loader.load();
63-
6462
if (!file.exists()) {
65-
mainSettings = new SettingsHolder(); //.__defaults(); todo load defaults from default config
66-
node.setValue(TypeToken.of(SettingsHolder.class), mainSettings);
67-
loader.save(node);
68-
} else {
69-
mainSettings = node.getValue(TypeToken.of(SettingsHolder.class));
63+
try (InputStream in = getResourceAsStream("default.conf")) {
64+
Files.copy(in, file.toPath());
65+
} catch (IOException e) {
66+
e.printStackTrace();
67+
}
7068
}
69+
70+
CommentedConfigurationNode node = loader.load();
71+
mainSettings = node.getValue(TypeToken.of(SettingsHolder.class));
7172
} catch (Exception e) {
7273
e.printStackTrace();
7374
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.jaimemartz.playerbalancer.PlayerBalancer;
55
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
66
import com.jaimemartz.playerbalancer.ping.ServerStatus;
7+
import com.jaimemartz.playerbalancer.section.SectionManager;
78
import com.jaimemartz.playerbalancer.section.ServerSection;
89
import com.jaimemartz.playerbalancer.utils.MessageUtils;
910
import net.md_5.bungee.api.ChatColor;
@@ -60,7 +61,9 @@ public void execute(CommandSender sender, String[] args) {
6061
case "info": {
6162
if (args.length == 2) {
6263
String input = args[1];
63-
ServerSection section = plugin.getSectionManager().getByName(input);
64+
SectionManager manager = plugin.getSectionManager();
65+
ServerSection section = manager.getByName(input);
66+
6467
if (section != null) {
6568
sender.sendMessage(new ComponentBuilder(Strings.repeat("-", 53)).strikethrough(true).color(ChatColor.GRAY).create());
6669

@@ -72,8 +75,8 @@ public void execute(CommandSender sender, String[] args) {
7275

7376
sender.sendMessage(new ComponentBuilder("Principal: ")
7477
.color(ChatColor.GRAY)
75-
.append(section.getProps().isPrincipal() ? "yes" : "no")
76-
.color(section.getProps().isPrincipal() ? ChatColor.GREEN : ChatColor.RED)
78+
.append(manager.isPrincipal(section) ? "yes" : "no")
79+
.color(manager.isPrincipal(section) ? ChatColor.GREEN : ChatColor.RED)
7780
.create());
7881

7982
if (section.getParent() != null) {
@@ -110,8 +113,8 @@ public void execute(CommandSender sender, String[] args) {
110113

111114
sender.sendMessage(new ComponentBuilder("Dummy: ")
112115
.color(ChatColor.GRAY)
113-
.append(section.getProps().isDummy() ? "yes" : "no")
114-
.color(section.getProps().isDummy() ? ChatColor.GREEN : ChatColor.RED)
116+
.append(manager.isDummy(section) ? "yes" : "no")
117+
.color(manager.isDummy(section) ? ChatColor.GREEN : ChatColor.RED)
115118
.create()
116119
);
117120

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSecti
6969
}
7070

7171
private ServerInfo fetchServer(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section, ProviderType provider, List<ServerInfo> servers) {
72-
if (plugin.getSettings().getGeneralProps().isAssignTargets()) {
72+
if (plugin.getSectionManager().isReiterative(section)) {
7373
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
7474
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
7575
ServerStatus status = plugin.getStatusManager().getStatus(target);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public void onDisconnect(PlayerDisconnectEvent event) {
2121
ProxiedPlayer player = event.getPlayer();
2222
PlayerLocker.unlock(player);
2323

24-
//Delete this if we want to keep assigned groups even when leaving
25-
if (plugin.getSettings().getGeneralProps().isAssignTargets()) {
26-
ServerAssignRegistry.clearAsssignedServers(player);
27-
}
24+
ServerAssignRegistry.clearAsssignedServers(player);
2825
}
2926
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void onConnect(ServerConnectEvent event) {
3131
new ConnectionIntent(plugin, player, section) {
3232
@Override
3333
public void connect(ServerInfo server, Callback<Boolean> callback) {
34-
if (plugin.getSettings().getGeneralProps().isAssignTargets()) {
34+
if (plugin.getSectionManager().isReiterative(section)) {
3535
ServerAssignRegistry.assignTarget(player, section, server);
3636
}
3737

@@ -52,7 +52,7 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
5252

5353
//Checks only for servers (not the section server)
5454
if (section.getMappedServers().contains(target)) {
55-
if (section.getProps().isDummy()) {
55+
if (plugin.getSectionManager().isDummy(section)) {
5656
return null;
5757
}
5858

@@ -62,7 +62,7 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo target) {
6262
}
6363

6464
if (player.getServer() != null && section.getMappedServers().contains(player.getServer().getInfo())) {
65-
if (plugin.getSettings().getGeneralProps().isAssignTargets()) {
65+
if (plugin.getSectionManager().isReiterative(section)) {
6666
ServerAssignRegistry.assignTarget(player, section, target);
6767
}
6868
return null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo from) {
116116
return null;
117117
}
118118

119-
if (props.isRestricted()) {
119+
if (props.isRestrictive()) {
120120
if (current.getPosition() >= 0 && target.getPosition() < 0) {
121121
return null;
122122
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import net.md_5.bungee.api.connection.ProxiedPlayer;
88

99
public class SectionCommand extends FallbackCommand {
10-
protected final ServerSection section;
10+
private final ServerSection section;
1111

1212
public SectionCommand(PlayerBalancer plugin, CommandProps props, ServerSection section) {
1313
super(plugin, props);

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jaimemartz.playerbalancer.section;
22

33
import com.jaimemartz.playerbalancer.PlayerBalancer;
4+
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
45
import net.md_5.bungee.api.config.ServerInfo;
56
import net.md_5.bungee.api.connection.ProxiedPlayer;
67
import net.md_5.bungee.api.connection.Server;
@@ -26,7 +27,7 @@ public void load() throws RuntimeException {
2627
plugin.getLogger().info("Loading sections from the config, this may take a while...");
2728
long starting = System.currentTimeMillis();
2829

29-
plugin.getSettings().getSections().forEach((name, prop) -> {
30+
plugin.getSettings().getBalancerProps().getSectionProps().forEach((name, prop) -> {
3031
plugin.getLogger().info(String.format("Construction of section with name \"%s\"", name));
3132
ServerSection object = new ServerSection(name, prop);
3233
sections.put(name, object);
@@ -70,7 +71,7 @@ public void flush() {
7071

7172
public void register(ServerInfo server, ServerSection section) {
7273
if (servers.containsKey(server)) {
73-
if (section.getProps().isDummy()) {
74+
if (isDummy(section)) {
7475
return;
7576
}
7677

@@ -113,23 +114,18 @@ public ServerSection getByPlayer(ProxiedPlayer player) {
113114
return getByServer(server.getInfo());
114115
}
115116

116-
public ServerSection getPrincipal() {
117-
return principal;
118-
}
119-
120117
/**
121118
* Calculates the position of a section in relation to other sections
122119
* This is supposed to be called on section construction
123120
* @param section the section we want to get the position of
124-
* @param principal the principal section
125121
* @return the position of {@param section}
126122
*/
127-
private int calculatePosition(ServerSection section, ServerSection principal) {
123+
private int calculatePosition(ServerSection section) {
128124
//Calculate above principal
129125
int iterations = 0;
130126
ServerSection current = section;
131127
while (current != null) {
132-
if (current.getProps().isPrincipal()) {
128+
if (current == principal) {
133129
return iterations;
134130
}
135131

@@ -154,6 +150,24 @@ private int calculatePosition(ServerSection section, ServerSection principal) {
154150
return iterations;
155151
}
156152

153+
public ServerSection getPrincipal() {
154+
return principal;
155+
}
156+
157+
public boolean isPrincipal(ServerSection section) {
158+
return section.equals(principal);
159+
}
160+
161+
public boolean isDummy(ServerSection section) {
162+
BalancerProps props = plugin.getSettings().getBalancerProps();
163+
return props.getDummySectionNames().contains(section.getName());
164+
}
165+
166+
public boolean isReiterative(ServerSection section) {
167+
BalancerProps props = plugin.getSettings().getBalancerProps();
168+
return props.getReiterativeSectionNames().contains(section.getName());
169+
}
170+
157171
public Map<String, ServerSection> getSections() {
158172
return sections;
159173
}

src/main/java/com/jaimemartz/playerbalancer/settings/props/features/KickHandlerProps.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class KickHandlerProps {
2121
private List<String> excludedSections;
2222

2323
@Setting
24-
private boolean restricted;
24+
private boolean restrictive;
2525

2626
@Setting(value = "force-principal")
2727
private boolean forcePrincipal;
@@ -64,12 +64,12 @@ public void setExcludedSections(List<String> excludedSections) {
6464
this.excludedSections = excludedSections;
6565
}
6666

67-
public boolean isRestricted() {
68-
return restricted;
67+
public boolean isRestrictive() {
68+
return restrictive;
6969
}
7070

71-
public void setRestricted(boolean restricted) {
72-
this.restricted = restricted;
71+
public void setRestrictive(boolean restrictive) {
72+
this.restrictive = restrictive;
7373
}
7474

7575
public boolean isForcePrincipal() {
@@ -103,7 +103,7 @@ public String toString() {
103103
", inverted=" + inverted +
104104
", reasons=" + reasons +
105105
", excludedSections=" + excludedSections +
106-
", restricted=" + restricted +
106+
", restrictive=" + restrictive +
107107
", forcePrincipal=" + forcePrincipal +
108108
", rules=" + rules +
109109
", debug=" + debug +

0 commit comments

Comments
 (0)