Skip to content

Commit 59dd26c

Browse files
committed
Moved to the text component api (first stage of dumping Faucet)
Renamed the plugin to PlayerBalancer (from LobbyBalancer) since this plugin does not only balance lobbies. I kinda have a issue with the naming of this plugin, I don't know what name is appropriate for it.
1 parent 4d25772 commit 59dd26c

24 files changed

+361
-280
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
# LobbyBalancer
1+
# PlayerBalancer
22
[Spigot Resource](https://www.spigotmc.org/resources/10788/)
33

4-
[![Build Status](https://travis-ci.com/jaime29010/LobbyBalancer.svg?token=2yUi9WpA9QzSbJx9eTmy&branch=master)](https://travis-ci.com/jaime29010/LobbyBalancer)
4+
[![Build Status](https://travis-ci.com/jaime29010/PlayerBalancer.svg?token=2yUi9WpA9QzSbJx9eTmy&branch=master)](https://travis-ci.com/jaime29010/LobbyBalancer)
55

66
### Things to do:
77
- [x] Get dummy sections able to have already registered servers on other sections
88
- [x] Add a new message for when a player gets connected to a server and repurpose the connecting one
99
- [ ] Add support for wildcards, contains, equalsIgnoreCase and regex at the same time
1010
- [ ] Add a identifier to get the servers of a section (auto complete)
11-
- [ ] Add tooltip when you hover over a server in /section info
11+
- [x] Add tooltip when you hover over a server in /section info
12+
- [ ] Stop using inventivetalent's deprecated bungee-update
1213
- [ ] Create a LobbyBalancer spigot addon that adds connector signs and placeholders
1314
- [ ] Separate the types of connections in classes instead of being in ConnectionIntent
1415
- [ ] Make the plugin API not be so dependent on a instance of LobbyBalancer
1516
- [ ] Separate connection providers in classes instead of being hardcoded in an enum
1617
- [ ] Make the feature `marker-descs` work per section
18+
- [ ] Implement fast connect (dimension change)
1719
- [ ] Unify the code that loads server into a section (duplicated at SectionManager and ServerSection)
1820
- [ ] Unify some of the code used in the FallbackCommand and SectionCommand
1921
- [x] Use https://github.com/kennedyoliveira/pastebin4j instead of jpaste

pom.xml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.jaimemartz</groupId>
88
<artifactId>playerbalancer</artifactId>
9-
<version>2.1</version>
9+
<version>2.1-dev</version>
1010
<name>LobbyBalancer</name>
1111

1212
<properties>
@@ -84,18 +84,6 @@
8484
<version>1.11-SNAPSHOT</version>
8585
<scope>provided</scope>
8686
</dependency>
87-
<dependency>
88-
<groupId>com.imaginarycode.minecraft</groupId>
89-
<artifactId>RedisBungee</artifactId>
90-
<version>0.3.8-SNAPSHOT</version>
91-
<scope>provided</scope>
92-
</dependency>
93-
<dependency>
94-
<groupId>org.inventivetalent.update</groupId>
95-
<artifactId>bungee</artifactId>
96-
<version>1.0.1</version>
97-
<scope>compile</scope>
98-
</dependency>
9987
<dependency>
10088
<groupId>ch.jalu</groupId>
10189
<artifactId>configme</artifactId>
@@ -108,29 +96,50 @@
10896
<version>1.2.0</version>
10997
<scope>compile</scope>
11098
</dependency>
99+
100+
101+
<!-- TODO Ditch this dependency, move to ConfigMe -->
111102
<dependency>
112103
<groupId>me.jaimemartz</groupId>
113104
<artifactId>faucet-bungee</artifactId>
114105
<version>1.0</version>
115106
<scope>compile</scope>
116107
</dependency>
108+
109+
<!-- TODO Replace with HTTP call to Spigot's API -->
110+
<dependency>
111+
<groupId>org.inventivetalent.update</groupId>
112+
<artifactId>bungee</artifactId>
113+
<version>1.0.1</version>
114+
<scope>compile</scope>
115+
</dependency>
116+
117+
<!-- TODO Replace with our own alternative to "RedisBunge" (maybe) -->
118+
<dependency>
119+
<groupId>com.imaginarycode.minecraft</groupId>
120+
<artifactId>RedisBungee</artifactId>
121+
<version>0.3.8-SNAPSHOT</version>
122+
<scope>provided</scope>
123+
</dependency>
124+
125+
117126
<dependency>
118127
<groupId>org.bstats</groupId>
119128
<artifactId>bstats-bungeecord</artifactId>
120129
<version>LATEST</version>
121130
<scope>compile</scope>
122131
</dependency>
123-
<dependency>
124-
<groupId>junit</groupId>
125-
<artifactId>junit</artifactId>
126-
<version>4.12</version>
127-
<scope>test</scope>
128-
</dependency>
129132
<dependency>
130133
<groupId>org.projectlombok</groupId>
131134
<artifactId>lombok</artifactId>
132135
<version>1.16.16</version>
133136
<scope>provided</scope>
134137
</dependency>
138+
<dependency>
139+
<groupId>junit</groupId>
140+
<artifactId>junit</artifactId>
141+
<version>4.12</version>
142+
<scope>test</scope>
143+
</dependency>
135144
</dependencies>
136145
</project>

src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java renamed to src/main/java/me/jaimemartz/lobbybalancer/PlayerBalancer.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
import java.io.IOException;
2424
import java.util.logging.Level;
2525

26-
public class LobbyBalancer extends Plugin {
26+
public class PlayerBalancer extends Plugin {
2727
private static final int LAST_VER_CONFIG_UPDATE = 20950000;
2828

2929
@Getter private ConfigFactory factory;
30+
3031
@Getter private boolean failed = false;
32+
3133
@Getter private StatusManager statusManager;
3234
@Getter private SectionManager sectionManager;
33-
@Getter private static LobbyBalancer instance;
35+
@Getter private static PlayerBalancer instance;
3436

3537
private Command fallbackCommand, mainCommand, manageCommand;
3638
private Listener connectListener, kickListener, messageListener, reloadListener;
@@ -116,7 +118,7 @@ private void enable() {
116118

117119
getLogger().info("The plugin has finished loading without any problems");
118120
} catch (RuntimeException e) {
119-
failed = true;
121+
this.failed = true;
120122
getLogger().severe("The plugin could not continue loading due to an unexpected exception");
121123
e.printStackTrace();
122124
}
@@ -175,11 +177,12 @@ private void disable() {
175177
ServerAssignRegistry.getTable().clear();
176178
}
177179
}
180+
178181
PlayerLocker.flush();
179182
failed = false;
180183
}
181184

182-
public void reloadPlugin() {
185+
public boolean reloadPlugin() {
183186
getLogger().info("Reloading the plugin...");
184187
long starting = System.currentTimeMillis();
185188

@@ -188,6 +191,8 @@ public void reloadPlugin() {
188191

189192
long ending = System.currentTimeMillis() - starting;
190193
getLogger().info(String.format("The plugin has been reloaded, took %sms", ending));
194+
195+
return !failed;
191196
}
192197

193198
public Configuration getConfigHandle() {

src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package me.jaimemartz.lobbybalancer.commands;
22

3-
import me.jaimemartz.faucet.Messager;
4-
import me.jaimemartz.lobbybalancer.LobbyBalancer;
3+
import me.jaimemartz.lobbybalancer.PlayerBalancer;
54
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
65
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
76
import me.jaimemartz.lobbybalancer.section.ServerSection;
7+
import me.jaimemartz.lobbybalancer.utils.MessageUtils;
88
import net.md_5.bungee.api.ChatColor;
99
import net.md_5.bungee.api.CommandSender;
10+
import net.md_5.bungee.api.chat.ComponentBuilder;
1011
import net.md_5.bungee.api.config.ServerInfo;
1112
import net.md_5.bungee.api.connection.ProxiedPlayer;
1213
import net.md_5.bungee.api.plugin.Command;
@@ -15,16 +16,15 @@
1516
import java.util.concurrent.Callable;
1617

1718
public class FallbackCommand extends Command {
18-
private final LobbyBalancer plugin;
19+
private final PlayerBalancer plugin;
1920

20-
public FallbackCommand(LobbyBalancer plugin) {
21+
public FallbackCommand(PlayerBalancer plugin) {
2122
super(ConfigEntries.FALLBACK_COMMAND_NAME.get(), ConfigEntries.FALLBACK_COMMAND_PERMISSION.get(), (ConfigEntries.FALLBACK_COMMAND_ALIASES.get().stream()).toArray(String[]::new));
2223
this.plugin = plugin;
2324
}
2425

2526
@Override
2627
public void execute(CommandSender sender, String[] args) {
27-
Messager msgr = new Messager(sender);
2828
if (sender instanceof ProxiedPlayer) {
2929
ProxiedPlayer player = (ProxiedPlayer) sender;
3030

@@ -33,7 +33,7 @@ public void execute(CommandSender sender, String[] args) {
3333

3434
if (section != null) {
3535
if ((ConfigEntries.FALLBACK_COMMAND_IGNORED_SECTIONS.get()).contains(section.getName())) {
36-
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
36+
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
3737
return null;
3838
}
3939

@@ -45,14 +45,14 @@ public void execute(CommandSender sender, String[] args) {
4545
if (section.getParent() != null) {
4646
target = section.getParent();
4747
} else {
48-
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
48+
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
4949
return null;
5050
}
5151
}
5252

5353
if (ConfigEntries.FALLBACK_COMMAND_RESTRICTED.get()) {
5454
if (section.getPosition() >= 0 && target.getPosition() < 0) {
55-
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
55+
MessageUtils.send(player, ConfigEntries.UNAVAILABLE_MESSAGE.get());
5656
return null;
5757
}
5858
}
@@ -74,15 +74,15 @@ public void execute(CommandSender sender, String[] args) {
7474
try {
7575
int number = Integer.parseInt(args[0]);
7676
if (number <= 0) {
77-
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
77+
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
7878
} else if (number > section.getServers().size()) {
79-
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
79+
MessageUtils.send(player, ConfigEntries.FAILURE_MESSAGE.get());
8080
} else {
8181
ServerInfo server = section.getSortedServers().get(number - 1);
8282
ConnectionIntent.direct(plugin, player, server);
8383
}
8484
} catch (NumberFormatException e) {
85-
msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get());
85+
MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get());
8686
}
8787
} else {
8888
ConnectionIntent.simple(plugin, player, section);
@@ -92,7 +92,7 @@ public void execute(CommandSender sender, String[] args) {
9292
//Nothing to do
9393
}
9494
} else {
95-
msgr.send(ChatColor.RED + "This command can only be executed by a player");
95+
sender.sendMessage(new ComponentBuilder("This command can only be executed by a player").color(ChatColor.RED).create());
9696
}
9797
}
9898
}
Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,61 @@
11
package me.jaimemartz.lobbybalancer.commands;
22

3-
import me.jaimemartz.faucet.Messager;
4-
import me.jaimemartz.lobbybalancer.LobbyBalancer;
3+
import me.jaimemartz.lobbybalancer.PlayerBalancer;
54
import me.jaimemartz.lobbybalancer.manager.PasteHelper;
65
import net.md_5.bungee.api.ChatColor;
76
import net.md_5.bungee.api.CommandSender;
7+
import net.md_5.bungee.api.chat.ComponentBuilder;
88
import net.md_5.bungee.api.plugin.Command;
9-
10-
import javax.net.ssl.HttpsURLConnection;
11-
import java.io.BufferedReader;
12-
import java.io.DataOutputStream;
13-
import java.io.IOException;
14-
import java.io.InputStreamReader;
15-
import java.net.MalformedURLException;
16-
import java.net.URL;
9+
import org.apache.commons.lang3.StringUtils;
1710

1811
public class MainCommand extends Command {
19-
private final LobbyBalancer plugin;
20-
private final URL hastebin;
12+
private final PlayerBalancer plugin;
2113

22-
public MainCommand(LobbyBalancer plugin) {
14+
public MainCommand(PlayerBalancer plugin) {
2315
super("balancer");
2416
this.plugin = plugin;
25-
26-
try {
27-
this.hastebin = new URL("https://hastebin.com/documents");
28-
} catch (MalformedURLException ignored) {}
2917
}
3018

3119
@Override
3220
public void execute(final CommandSender sender, String[] args) {
33-
Messager msgr = new Messager(sender);
34-
if (args.length == 0) {
35-
msgr.send(
36-
"&7&m-----------------------------------------------------",
37-
"&7Information: LobbyBalancer version " + plugin.getDescription().getVersion(),
38-
"&7Available commands:",
39-
"&3/balancer &7- &cShows this message",
40-
"&3/balancer paste &7- &cCreates a paste with the important files",
41-
"&3/balancer reload &7- &cReloads the plugin completely",
42-
"&7&m-----------------------------------------------------"
43-
);
44-
} else {
45-
switch (args[0]) {
21+
if (args.length != 0) {
22+
switch (args[0].toLowerCase()) {
4623
case "paste": {
4724
if (sender.hasPermission("lobbybalancer.admin")) {
4825
PasteHelper.PLUGIN.send(plugin, sender, "Plugin config paste link: {link}");
4926
PasteHelper.BUNGEE.send(plugin, sender, "Bungee config paste link (sensitive): {link}");
5027
} else {
51-
msgr.send(ChatColor.RED + "You do not have permission to execute this command!");
28+
sender.sendMessage(new ComponentBuilder("You do not have permission to execute this command!").color(ChatColor.RED).create());
5229
}
5330
break;
5431
}
5532

5633
case "reload": {
5734
if (sender.hasPermission("lobbybalancer.admin")) {
58-
msgr.send(ChatColor.GREEN + "Reloading the configuration, this may take a while...");
59-
plugin.reloadPlugin();
60-
msgr.send(ChatColor.GREEN + "The configuration has been reloaded");
35+
sender.sendMessage(new ComponentBuilder("Reloading the configuration, this may take a while...").color(ChatColor.GREEN).create());
36+
if (plugin.reloadPlugin()) {
37+
sender.sendMessage(new ComponentBuilder("The plugin has successfully reloaded").color(ChatColor.GREEN).create());
38+
} else {
39+
sender.sendMessage(new ComponentBuilder("Something went badly while reloading the plugin").color(ChatColor.RED).create());
40+
}
6141
} else {
62-
msgr.send(ChatColor.RED + "You do not have permission to execute this command!");
42+
sender.sendMessage(new ComponentBuilder("You do not have permission to execute this command!").color(ChatColor.RED).create());
6343
}
6444
break;
6545
}
6646

6747
default: {
68-
msgr.send(ChatColor.RED + "This is not a valid argument for this command!");
48+
sender.sendMessage(new ComponentBuilder("This is not a valid argument for this command!").color(ChatColor.RED).create());
6949
}
7050
}
51+
} else {
52+
sender.sendMessage(new ComponentBuilder(StringUtils.repeat('-', 53)).strikethrough(true).color(ChatColor.GRAY).create());
53+
sender.sendMessage(new ComponentBuilder("LobbyBalancer " + plugin.getDescription().getVersion()).color(ChatColor.GRAY).create());
54+
sender.sendMessage(new ComponentBuilder("Available commands:").color(ChatColor.GRAY).create());
55+
sender.sendMessage(new ComponentBuilder("/balancer").color(ChatColor.AQUA).append(" - ").color(ChatColor.GRAY).append("Shows you this message").color(ChatColor.RED).create());
56+
sender.sendMessage(new ComponentBuilder("/balancer paste").color(ChatColor.AQUA).append(" - ").color(ChatColor.GRAY).append("Creates a paste with the important files").color(ChatColor.RED).create());
57+
sender.sendMessage(new ComponentBuilder("/balancer reload").color(ChatColor.AQUA).append(" - ").color(ChatColor.GRAY).append("Reloads the plugin completely").color(ChatColor.RED).create());
58+
sender.sendMessage(new ComponentBuilder(StringUtils.repeat('-', 53)).strikethrough(true).color(ChatColor.GRAY).create());
7159
}
7260
}
7361
}

0 commit comments

Comments
 (0)