Skip to content

Commit 4d25772

Browse files
committed
Now using pastebin4j
1 parent 8dd1a0c commit 4d25772

File tree

19 files changed

+67
-1522
lines changed

19 files changed

+67
-1522
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- [ ] Make the feature `marker-descs` work per section
1717
- [ ] Unify the code that loads server into a section (duplicated at SectionManager and ServerSection)
1818
- [ ] Unify some of the code used in the FallbackCommand and SectionCommand
19-
- [ ] Use https://github.com/kennedyoliveira/pastebin4j instead of jpaste
19+
- [x] Use https://github.com/kennedyoliveira/pastebin4j instead of jpaste
2020
- [ ] (!) Make the section initialization work in stages instead of being hardcoded
2121
- [ ] (!) Ditch the faucet dependency and use [ConfigMe](https://github.com/AuthMe/ConfigMe) and [DependencyInjector](https://github.com/ljacqu/DependencyInjector) instead
2222
- [ ] Use a separate file for configuring the sections, must be done alongside the previous item

pom.xml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>me.jaimemartz</groupId>
8-
<artifactId>lobbybalancer</artifactId>
9-
<version>2.0.9.9</version>
7+
<groupId>com.jaimemartz</groupId>
8+
<artifactId>playerbalancer</artifactId>
9+
<version>2.1</version>
1010
<name>LobbyBalancer</name>
1111

1212
<properties>
@@ -32,7 +32,7 @@
3232
</repository>
3333
<repository>
3434
<id>bstats-repo</id>
35-
<url>https://repo.bstats.org/content/groups/public/</url>
35+
<url>http://repo.bstats.org/content/repositories/releases/</url>
3636
</repository>
3737
</repositories>
3838
<build>
@@ -96,6 +96,18 @@
9696
<version>1.0.1</version>
9797
<scope>compile</scope>
9898
</dependency>
99+
<dependency>
100+
<groupId>ch.jalu</groupId>
101+
<artifactId>configme</artifactId>
102+
<version>0.4</version>
103+
<scope>compile</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>com.github.kennedyoliveira</groupId>
107+
<artifactId>pastebin4j</artifactId>
108+
<version>1.2.0</version>
109+
<scope>compile</scope>
110+
</dependency>
99111
<dependency>
100112
<groupId>me.jaimemartz</groupId>
101113
<artifactId>faucet-bungee</artifactId>

src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import net.md_5.bungee.api.plugin.Listener;
1717
import net.md_5.bungee.api.plugin.Plugin;
1818
import net.md_5.bungee.config.Configuration;
19-
import org.bstats.Metrics;
19+
import org.bstats.bungeecord.Metrics;
20+
import org.bstats.bungeecord.Metrics.SingleLineChart;
2021
import org.inventivetalent.update.bungee.BungeeUpdater;
2122

2223
import java.io.IOException;
@@ -48,7 +49,7 @@ public void onEnable() {
4849

4950
//Metrics (https://bstats.org/)
5051
Metrics metrics = new Metrics(this);
51-
metrics.addCustomChart(new Metrics.SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
52+
metrics.addCustomChart(new SingleLineChart("configured_sections", () -> sectionManager.getSections().size()));
5253
}
5354

5455
private void enable() {
@@ -60,7 +61,7 @@ private void enable() {
6061
String text = ConfigEntries.CONFIG_VERSION.get();
6162
int configVersion = DigitUtils.getDigits(text, 8);
6263
if (configVersion < LAST_VER_CONFIG_UPDATE) {
63-
failed = true;
64+
this.failed = true;
6465
throw new IllegalStateException("Your config is outdated, please reset it and configure it again");
6566
}
6667

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@
77
import net.md_5.bungee.api.CommandSender;
88
import net.md_5.bungee.api.plugin.Command;
99

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;
17+
1018
public class MainCommand extends Command {
1119
private final LobbyBalancer plugin;
20+
private final URL hastebin;
1221

1322
public MainCommand(LobbyBalancer plugin) {
1423
super("balancer");
1524
this.plugin = plugin;
25+
26+
try {
27+
this.hastebin = new URL("https://hastebin.com/documents");
28+
} catch (MalformedURLException ignored) {}
1629
}
1730

1831
@Override
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package me.jaimemartz.lobbybalancer.manager;
22

3+
import com.github.kennedyoliveira.pastebin4j.*;
34
import com.google.common.io.CharStreams;
45
import me.jaimemartz.lobbybalancer.LobbyBalancer;
56
import net.md_5.bungee.api.ChatColor;
67
import net.md_5.bungee.api.CommandSender;
78
import net.md_5.bungee.api.chat.ComponentBuilder;
89
import net.md_5.bungee.api.scheduler.ScheduledTask;
9-
import org.jpaste.exceptions.PasteException;
10-
import org.jpaste.pastebin.PasteExpireDate;
11-
import org.jpaste.pastebin.PastebinLink;
12-
import org.jpaste.pastebin.PastebinPaste;
1310

1411
import java.io.File;
1512
import java.io.FileInputStream;
@@ -25,21 +22,25 @@ public String paste(LobbyBalancer plugin) throws Exception {
2522
return "File does not exist";
2623
}
2724

28-
PastebinPaste paste = new PastebinPaste();
29-
paste.setPasteTitle("{name} ({version} on {bungee_version}) Configuration"
25+
GuestPaste paste = new GuestPaste();
26+
paste.setTitle("{name} ({version} on {bungee_version}) Configuration"
3027
.replace("{name}", plugin.getDescription().getName())
3128
.replace("{version}", plugin.getDescription().getVersion())
3229
.replace("{bungee_version}", plugin.getProxy().getVersion())
3330
);
34-
paste.setDeveloperKey(DEVELOPER_KEY);
35-
paste.setPasteExpireDate(PasteExpireDate.ONE_MONTH);
36-
paste.setVisibility(PastebinPaste.VISIBILITY_UNLISTED);
37-
paste.setPasteFormat("yaml");
31+
32+
paste.setExpiration(PasteExpiration.ONE_MONTH);
33+
paste.setVisibility(PasteVisibility.UNLISTED);
34+
paste.setHighLight(PasteHighLight.YAML);
35+
3836
try (FileInputStream stream = new FileInputStream(file)) {
39-
paste.setContents(CharStreams.toString(new InputStreamReader(stream, "UTF-8")));
37+
try (InputStreamReader reader = new InputStreamReader(stream, "UTF-8")) {
38+
String content = CharStreams.toString(reader);
39+
paste.setContent(content);
40+
}
4041
}
41-
PastebinLink link = paste.paste();
42-
return link.getLink().toString();
42+
43+
return paste.paste(credentials);
4344
}
4445
},
4546
BUNGEE {
@@ -50,47 +51,47 @@ public String paste(LobbyBalancer plugin) throws Exception {
5051
return "File does not exist";
5152
}
5253

53-
PastebinPaste paste = new PastebinPaste();
54-
paste.setPasteTitle("{name} ({version}) Configuration"
54+
GuestPaste paste = new GuestPaste();
55+
paste.setTitle("{name} ({version}) Configuration"
5556
.replace("{name}", plugin.getProxy().getName())
5657
.replace("{version}", plugin.getProxy().getVersion())
5758
);
58-
paste.setDeveloperKey(DEVELOPER_KEY);
59-
paste.setPasteExpireDate(PasteExpireDate.ONE_MONTH);
60-
paste.setVisibility(PastebinPaste.VISIBILITY_UNLISTED);
61-
paste.setPasteFormat("yaml");
59+
60+
paste.setExpiration(PasteExpiration.ONE_MONTH);
61+
paste.setVisibility(PasteVisibility.UNLISTED);
62+
paste.setHighLight(PasteHighLight.YAML);
63+
6264
try (FileInputStream stream = new FileInputStream(file)) {
63-
paste.setContents(CharStreams.toString(new InputStreamReader(stream, "UTF-8")));
65+
try (InputStreamReader reader = new InputStreamReader(stream, "UTF-8")) {
66+
String content = CharStreams.toString(reader);
67+
content = content.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "X.X.X.X");
68+
paste.setContent(content);
69+
}
6470
}
65-
PastebinLink link = paste.paste();
66-
return link.getLink().toString();
71+
72+
return paste.paste(credentials);
6773
}
6874
};
6975

70-
public static final String DEVELOPER_KEY = "e3ff18d8fb001a3ece08ae0d7d4a87bd";
7176
private String link;
7277
private ScheduledTask task = null;
7378

7479
public void send(LobbyBalancer plugin, CommandSender sender, String message) {
7580
try {
76-
sender.sendMessage(new ComponentBuilder(message.replace("{link}", link == null ? link = paste(plugin) : link)
77-
).color(ChatColor.GREEN).create());
81+
sender.sendMessage(new ComponentBuilder(message.replace("{link}", link == null ? link = paste(plugin) : link)).color(ChatColor.GREEN).create());
82+
7883
if (task != null) {
7984
plugin.getProxy().getScheduler().cancel(task);
8085
}
86+
8187
task = plugin.getProxy().getScheduler().schedule(plugin, () -> link = null, 5, TimeUnit.MINUTES);
82-
} catch (PasteException e) {
83-
if (e.getMessage().equals("Failed to generate paste: Post limit, maximum pastes per 24h reached")) {
84-
sender.sendMessage(new ComponentBuilder("The file could not be pasted, your ip has reached the 10 pastes per day limit").color(ChatColor.RED).create());
85-
} else {
86-
sender.sendMessage(new ComponentBuilder("An unexpected error occurred while pasting the file").color(ChatColor.RED).create());
87-
}
88-
e.printStackTrace();
8988
} catch (Exception e) {
9089
sender.sendMessage(new ComponentBuilder("An internal error occurred while attempting to perform this command").color(ChatColor.RED).create());
9190
e.printStackTrace();
9291
}
9392
}
9493

9594
public abstract String paste(LobbyBalancer plugin) throws Exception;
95+
96+
private static final AccountCredentials credentials = new AccountCredentials("e3ff18d8fb001a3ece08ae0d7d4a87bd");
9697
}

src/main/java/org/jpaste/AbstractPaste.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/main/java/org/jpaste/AbstractPasteLink.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/org/jpaste/exceptions/PasteException.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/org/jpaste/pastebin/PasteExpireDate.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)