Skip to content

Commit 89a5b37

Browse files
committed
Some progress and circleci
1 parent ce9db9e commit 89a5b37

File tree

20 files changed

+225
-291
lines changed

20 files changed

+225
-291
lines changed

.circleci/config.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Java Maven CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: circleci/openjdk:8-jdk
11+
12+
# Specify service dependencies here if necessary
13+
# CircleCI maintains a library of pre-built images
14+
# documented at https://circleci.com/docs/2.0/circleci-images/
15+
# - image: circleci/postgres:9.4
16+
17+
working_directory: ~/repo
18+
19+
environment:
20+
# Customize the JVM maximum heap limit
21+
MAVEN_OPTS: -Xmx3200m
22+
23+
steps:
24+
- checkout
25+
26+
# Download and cache dependencies
27+
- restore_cache:
28+
keys:
29+
- v1-dependencies-{{ checksum "pom.xml" }}
30+
# fallback to using the latest cache if no exact match is found
31+
- v1-dependencies-
32+
33+
- run: mvn dependency:go-offline
34+
35+
- save_cache:
36+
paths:
37+
- ~/.m2
38+
key: v1-dependencies-{{ checksum "pom.xml" }}
39+
40+
# run tests!
41+
- run: mvn integration-test

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@
100100
<artifactId>configurate-hocon</artifactId>
101101
<version>3.3</version>
102102
<scope>compile</scope>
103+
<exclusions>
104+
<exclusion>
105+
<groupId>com.google.guava</groupId>
106+
<artifactId>guava</artifactId>
107+
</exclusion>
108+
</exclusions>
103109
</dependency>
104110
<dependency>
105111
<groupId>org.bstats</groupId>

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
1212
import com.jaimemartz.playerbalancer.ping.StatusManager;
1313
import com.jaimemartz.playerbalancer.section.SectionManager;
14-
import com.jaimemartz.playerbalancer.section.ServerSection;
1514
import com.jaimemartz.playerbalancer.settings.MainSettings;
16-
import com.jaimemartz.playerbalancer.settings.serializers.SectionSerializer;
1715
import net.md_5.bungee.api.plugin.Command;
1816
import net.md_5.bungee.api.plugin.Listener;
1917
import net.md_5.bungee.api.plugin.Plugin;
@@ -52,21 +50,20 @@ private void enable() {
5250
if (!getDataFolder().exists())
5351
getDataFolder().mkdir();
5452

55-
File file = new File(getDataFolder(), "default.conf");
53+
File file = new File(getDataFolder(), "plugin.conf");
5654

5755
if (loader == null) {
5856
TypeSerializerCollection serializers = TypeSerializers.getDefaultSerializers().newChild();
59-
serializers.registerType(TypeToken.of(ServerSection.class), new SectionSerializer());
57+
//serializers.registerType(TypeToken.of(ServerSection.class), new SectionSerializer());
6058
ConfigurationOptions options = ConfigurationOptions.defaults().setSerializers(serializers);
61-
//options.setMapFactory(MapFactories.insertionOrdered());
6259
loader = HoconConfigurationLoader.builder().setFile(file).setDefaultOptions(options).build();
6360
}
6461

6562
try {
6663
CommentedConfigurationNode node = loader.load();
6764

6865
if (!file.exists()) {
69-
mainSettings = new MainSettings()._defaults();
66+
mainSettings = new MainSettings().__defaults();
7067
node.setValue(TypeToken.of(MainSettings.class), mainSettings);
7168
loader.save(node);
7269
} else {

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.jaimemartz.playerbalancer.PlayerBalancer;
44
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
55
import com.jaimemartz.playerbalancer.section.ServerSection;
6-
import com.jaimemartz.playerbalancer.settings.MainSettings;
6+
import com.jaimemartz.playerbalancer.settings.props.FallbackCommandProps;
77
import com.jaimemartz.playerbalancer.settings.props.MessagesProps;
88
import com.jaimemartz.playerbalancer.settings.shared.CommandProps;
99
import com.jaimemartz.playerbalancer.utils.MessageUtils;
@@ -17,12 +17,12 @@
1717
public class FallbackCommand extends Command {
1818
protected final PlayerBalancer plugin;
1919
protected final MessagesProps messages;
20-
protected final MainSettings settings;
20+
private final FallbackCommandProps props;
2121

2222
public FallbackCommand(PlayerBalancer plugin, CommandProps props) {
2323
super(props.getName(), props.getPermission(), props.getAliasesArray());
24-
this.settings = plugin.getSettings();
25-
this.messages = settings.getMessagesProps();
24+
this.props = plugin.getSettings().getFallbackCommandProps();
25+
this.messages = plugin.getSettings().getMessagesProps();
2626
this.plugin = plugin;
2727
}
2828

@@ -43,6 +43,7 @@ public void execute(CommandSender sender, String[] args) {
4343
} else {
4444
ServerInfo server = target.getSortedServers().get(number - 1);
4545
ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {
46+
//todo something missing
4647
});
4748
}
4849
} catch (NumberFormatException e) {
@@ -61,24 +62,19 @@ public ServerSection getSection(ProxiedPlayer player) {
6162
ServerSection current = plugin.getSectionManager().getByPlayer(player);
6263

6364
if (current != null) {
64-
if (settings.getFallbackCommandProps().getExcludedSections().contains(current.getName())) {
65+
if (props.getExcludedSections().contains(current.getName())) {
6566
MessageUtils.send(player, messages.getUnavailableServerMessage());
6667
return null;
6768
}
6869

69-
String bind = settings.getFallbackCommandProps().getRules().get(current.getName());
70-
ServerSection target = plugin.getSectionManager().getByName(bind);
71-
70+
ServerSection target = plugin.getSectionManager().getBind(props.getRules(), current)
71+
.orElse(current.getParent());
7272
if (target == null) {
73-
if (current.getParent() != null) {
74-
target = current.getParent();
75-
} else {
76-
MessageUtils.send(player, messages.getUnavailableServerMessage());
77-
return null;
78-
}
73+
MessageUtils.send(player, messages.getUnavailableServerMessage());
74+
return null;
7975
}
8076

81-
if (settings.getFallbackCommandProps().isRestrictive()) {
77+
if (props.isRestrictive()) {
8278
if (current.getPosition() >= 0 && target.getPosition() < 0) {
8379
MessageUtils.send(player, messages.getUnavailableServerMessage());
8480
return null;
@@ -87,7 +83,7 @@ public ServerSection getSection(ProxiedPlayer player) {
8783

8884
return target;
8985
} else {
90-
if (settings.getGeneralProps().isFallbackPrincipal()) {
86+
if (plugin.getSettings().getGeneralProps().isFallbackPrincipal()) {
9187
return plugin.getSectionManager().getPrincipal();
9288
}
9389
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void execute(CommandSender sender, String[] args) {
5252
MessageUtils.send(sender, plugin.getSettings().getMessagesProps().getUnknownSectionMessage());
5353
}
5454
} else {
55-
sender.sendMessage(new ComponentBuilder("Usage: /balancer connect <section> [player]").color(ChatColor.RED).create());
55+
sender.sendMessage(new ComponentBuilder("Usage: /section connect <section> [player]").color(ChatColor.RED).create());
5656
}
5757
break;
5858
}
@@ -204,7 +204,7 @@ public void execute(CommandSender sender, String[] args) {
204204
MessageUtils.send(sender, plugin.getSettings().getMessagesProps().getUnknownSectionMessage());
205205
}
206206
} else {
207-
sender.sendMessage(new ComponentBuilder("Usage: /balancer info <section>").color(ChatColor.RED).create());
207+
sender.sendMessage(new ComponentBuilder("Usage: /section info <section>").color(ChatColor.RED).create());
208208
}
209209
break;
210210
}

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

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.jaimemartz.playerbalancer.connection.ConnectionIntent;
55
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
66
import com.jaimemartz.playerbalancer.section.ServerSection;
7+
import com.jaimemartz.playerbalancer.settings.props.KickHandlerProps;
8+
import com.jaimemartz.playerbalancer.settings.props.MessagesProps;
79
import com.jaimemartz.playerbalancer.utils.MessageUtils;
810
import net.md_5.bungee.api.Callback;
911
import net.md_5.bungee.api.chat.TextComponent;
@@ -19,9 +21,13 @@
1921
import java.util.concurrent.TimeUnit;
2022

2123
public class ServerKickListener implements Listener {
24+
private final KickHandlerProps props;
2225
private final PlayerBalancer plugin;
26+
private final MessagesProps messages;
2327

2428
public ServerKickListener(PlayerBalancer plugin) {
29+
this.props = plugin.getSettings().getKickHandlerProps();
30+
this.messages = plugin.getSettings().getMessagesProps();
2531
this.plugin = plugin;
2632
}
2733

@@ -30,35 +36,60 @@ public void onKick(ServerKickEvent event) {
3036
ProxiedPlayer player = event.getPlayer();
3137
ServerInfo from = event.getKickedFrom();
3238

33-
ServerSection section = getSection(player, from);
34-
35-
if (section != null) {
36-
List<ServerInfo> servers = new ArrayList<>();
37-
servers.addAll(section.getMappedServers());
38-
servers.remove(from);
39-
40-
new ConnectionIntent(plugin, player, section, servers) {
41-
@Override
42-
public void connect(ServerInfo server, Callback<Boolean> callback) {
43-
PlayerLocker.lock(player);
44-
MessageUtils.send(player, plugin.getSettings().getMessagesProps().getKickMessage(),
45-
(str) -> str.replace("{from}", from.getName())
46-
.replace("{to}", server.getName())
47-
.replace("{reason}", event.getKickReason()));
48-
event.setCancelled(true);
49-
event.setCancelServer(server);
50-
plugin.getProxy().getScheduler().schedule(plugin, () -> {
51-
PlayerLocker.unlock(player);
52-
}, 5, TimeUnit.SECONDS);
53-
callback.done(true, null);
54-
}
55-
};
39+
boolean matches = false;
40+
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
41+
42+
for (String string : props.getReasons()) {
43+
if (reason.matches(string) || reason.contains(string)) { //todo improve this
44+
matches = true;
45+
break;
46+
}
47+
}
48+
49+
if (props.isInverted()) {
50+
matches = !matches;
51+
}
52+
53+
if (props.isDebug()) {
54+
plugin.getLogger().info(String.format("The player %s got kicked from %s, reason: %s. Matched reasons: %s",
55+
player.getName(),
56+
from.getName(),
57+
TextComponent.toPlainText(event.getKickReasonComponent()),
58+
matches
59+
));
60+
}
61+
62+
if (matches) {
63+
ServerSection section = getSection(player, from);
64+
65+
if (section != null) {
66+
List<ServerInfo> servers = new ArrayList<>();
67+
servers.addAll(section.getMappedServers());
68+
servers.remove(from);
69+
70+
new ConnectionIntent(plugin, player, section, servers) {
71+
@Override
72+
public void connect(ServerInfo server, Callback<Boolean> callback) {
73+
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()));
78+
event.setCancelled(true);
79+
event.setCancelServer(server);
80+
plugin.getProxy().getScheduler().schedule(plugin, () -> {
81+
PlayerLocker.unlock(player);
82+
}, 5, TimeUnit.SECONDS);
83+
callback.done(true, null);
84+
}
85+
};
86+
}
5687
}
5788
}
5889

5990
private ServerSection getSection(ProxiedPlayer player, ServerInfo from) {
6091
if (player.getServer() == null) {
61-
if (plugin.getSettings().getKickHandlerProps().isForcePrincipal()) {
92+
if (props.isForcePrincipal()) {
6293
return plugin.getSectionManager().getPrincipal();
6394
} else {
6495
return null;
@@ -72,52 +103,32 @@ private ServerSection getSection(ProxiedPlayer player, ServerInfo from) {
72103
ServerSection current = plugin.getSectionManager().getByServer(from);
73104

74105
if (current != null) {
75-
if (plugin.getSettings().getKickHandlerProps().getExcludedSections().contains(current.getName())) {
106+
if (props.getExcludedSections().contains(current.getName())) {
76107
return null;
77108
}
78109
}
79110

80-
boolean matches = false;
81-
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
82-
83-
for (String string : settings.getProperty(ReconnectorProperties.REASONS)) {
84-
if (reason.matches(string) || reason.contains(string)) {
85-
matches = true;
86-
break;
111+
if (current != null) {
112+
ServerSection target = plugin.getSectionManager().getBind(props.getRules(), current)
113+
.orElse(current.getParent());
114+
if (target == null) {
115+
MessageUtils.send(player, messages.getUnavailableServerMessage());
116+
return null;
87117
}
88-
}
89-
90-
if (settings.getProperty(ReconnectorProperties.INVERTED)) {
91-
matches.set(!matches.get());
92-
}
93-
94-
if (settings.getProperty(ReconnectorProperties.DEBUG)) {
95-
plugin.getLogger().info(String.format("Kick Reason: \"%s\", Found Match: %s", TextComponent.toPlainText(event.getKickReasonComponent()), matches));
96-
}
97118

98-
if (matches.get()) {
99-
if (current != null) {
100-
MapBean rules = settings.getProperty(CommandProperties.RULES);
101-
String bind = rules.getMap().get(current.getName());
102-
ServerSection target = holder.getByName(bind);
103-
104-
if (target == null) {
105-
target = current.getParentName();
106-
}
107-
108-
if (settings.getProperty(ReconnectorProperties.RESTRICTED)) {
109-
if (current.getPosition() >= 0 && target.getPosition() < 0) {
110-
return null;
111-
}
119+
if (props.isRestricted()) {
120+
if (current.getPosition() >= 0 && target.getPosition() < 0) {
121+
return null;
112122
}
123+
}
113124

114-
return target;
115-
} else {
116-
if (settings.getProperty(GeneralProperties.FALLBACK_PRINCIPAL)) {
117-
return holder.getPrincipal();
118-
}
125+
return target;
126+
} else {
127+
if (plugin.getSettings().getGeneralProps().isFallbackPrincipal()) {
128+
return plugin.getSectionManager().getPrincipal();
119129
}
120130
}
131+
121132
return null;
122133
}
123134
}

src/main/java/com/jaimemartz/playerbalancer/manager/PasteHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public URL paste(PlayerBalancer plugin) throws Exception {
4444

4545
paste.setExpiration(GuestPaste.Expiration.ONE_MONTH);
4646
paste.setExposure(GuestPaste.Exposure.UNLISTED);
47-
paste.setFormat("json");
47+
paste.setFormat("properties");
4848

4949
return paste.paste();
5050
}

0 commit comments

Comments
 (0)