Skip to content

Commit 4e4289c

Browse files
committed
Little OCD changes
1 parent 3a3aa2b commit 4e4289c

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
- [ ] Implement a way to redirect premium players to a section and cracked ones to other section (not sure how this works)
2020
- [ ] Unify the code that loads server into a section (duplicated at SectionManager and ServerSection)
2121
- [ ] Unify some of the code used in the FallbackCommand and SectionCommand
22-
- [x] Use https://github.com/kennedyoliveira/pastebin4j instead of jpaste
2322
- [ ] (!) Make the section initialization work in stages instead of being hardcoded
2423
- [ ] (!) Ditch the faucet dependency and use [ConfigMe](https://github.com/AuthMe/ConfigMe) and [DependencyInjector](https://github.com/ljacqu/DependencyInjector) instead
2524
- [ ] Use a separate file for configuring the sections, must be done alongside the previous item

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.io.CharStreams;
44
import com.jaimemartz.playerbalancer.PlayerBalancer;
55
import com.jaimemartz.playerbalancer.utils.GuestPaste;
6+
import com.jaimemartz.playerbalancer.utils.GuestPaste.PasteException;
67
import net.md_5.bungee.api.ChatColor;
78
import net.md_5.bungee.api.CommandSender;
89
import net.md_5.bungee.api.chat.ClickEvent;
@@ -20,13 +21,13 @@
2021
public enum PasteHelper {
2122
PLUGIN((sender, url) -> {
2223
if (sender instanceof ProxiedPlayer) {
23-
sender.sendMessage(new ComponentBuilder("Click me for the plugin configuration")
24+
sender.sendMessage(new ComponentBuilder("Click me for the PlayerBalancer configuration")
2425
.event(new ClickEvent(ClickEvent.Action.OPEN_URL, url.toString()))
2526
.color(ChatColor.GREEN)
2627
.create()
2728
);
2829
} else {
29-
sender.sendMessage(new ComponentBuilder("Plugin configuration link: " + url.toString()).create());
30+
sender.sendMessage(new ComponentBuilder("PlayerBalancer configuration link: " + url.toString()).create());
3031
}
3132
}) {
3233
@Override
@@ -37,7 +38,7 @@ public URL paste(PlayerBalancer plugin) throws Exception {
3738
String content = CharStreams.toString(reader);
3839
GuestPaste paste = new GuestPaste("e3ff18d8fb001a3ece08ae0d7d4a87bd", content);
3940

40-
paste.setName("{name} ({version} on {bungee_version}) Configuration"
41+
paste.setName("{name} ({version} on {bungee_version})"
4142
.replace("{name}", plugin.getDescription().getName())
4243
.replace("{version}", plugin.getDescription().getVersion())
4344
.replace("{bungee_version}", plugin.getProxy().getVersion())
@@ -52,6 +53,7 @@ public URL paste(PlayerBalancer plugin) throws Exception {
5253
}
5354
}
5455
},
56+
5557
BUNGEE((sender, url) -> {
5658
if (sender instanceof ProxiedPlayer) {
5759
sender.sendMessage(new ComponentBuilder("Click me for the BungeeCord configuration")
@@ -72,7 +74,7 @@ public URL paste(PlayerBalancer plugin) throws Exception {
7274
content = content.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "?.?.?.?");
7375
GuestPaste paste = new GuestPaste("e3ff18d8fb001a3ece08ae0d7d4a87bd", content);
7476

75-
paste.setName("{name} ({version}) Configuration"
77+
paste.setName("{name} ({version})"
7678
.replace("{name}", plugin.getProxy().getName())
7779
.replace("{version}", plugin.getProxy().getVersion())
7880
);
@@ -105,7 +107,7 @@ public void send(PlayerBalancer plugin, CommandSender sender) {
105107
task = plugin.getProxy().getScheduler().schedule(plugin, () -> {
106108
url = null;
107109
}, 5, TimeUnit.MINUTES);
108-
} catch (GuestPaste.PasteException e) {
110+
} catch (PasteException e) {
109111
sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage())
110112
.color(ChatColor.RED)
111113
.create()

src/main/java/com/jaimemartz/playerbalancer/utils/GuestPaste.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class GuestPaste {
1919
private final String key;
2020
private final String code;
2121

22-
private String name;
23-
private String format;
24-
private Expiration expiration;
25-
private Exposure exposure;
22+
private String name = null;
23+
private String format = null;
24+
private Expiration expiration = null;
25+
private Exposure exposure = null;
2626

2727
public GuestPaste(String key, String code) {
2828
this.key = key;
@@ -50,11 +50,11 @@ public URL paste() throws Exception {
5050
}
5151

5252
if (expiration != null) {
53-
params.add(new SimpleEntry<>("api_paste_expire_date", expiration.getValue()));
53+
params.add(new SimpleEntry<>("api_paste_expire_date", expiration.value));
5454
}
5555

5656
if (exposure != null) {
57-
params.add(new SimpleEntry<>("api_paste_private", String.valueOf(exposure.getValue())));
57+
params.add(new SimpleEntry<>("api_paste_private", String.valueOf(exposure.value)));
5858
}
5959

6060
StringBuilder output = new StringBuilder();
@@ -75,20 +75,18 @@ public URL paste() throws Exception {
7575

7676
int status = con.getResponseCode();
7777
if (status >= 200 && status < 300) {
78-
try (InputStreamReader isr = new InputStreamReader(con.getInputStream())) {
79-
try (BufferedReader br = new BufferedReader(isr)) {
80-
String inputLine;
81-
StringBuilder response = new StringBuilder();
82-
83-
while ((inputLine = br.readLine()) != null) {
84-
response.append(inputLine);
85-
}
86-
87-
try {
88-
return new URL(response.toString());
89-
} catch (MalformedURLException e) {
90-
throw new PasteException("Pastebin error: " + response.toString());
91-
}
78+
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
79+
String inputLine;
80+
StringBuilder response = new StringBuilder();
81+
82+
while ((inputLine = br.readLine()) != null) {
83+
response.append(inputLine);
84+
}
85+
86+
try {
87+
return new URL(response.toString());
88+
} catch (MalformedURLException e) {
89+
throw new PasteException(response.toString());
9290
}
9391
}
9492
} else {

0 commit comments

Comments
 (0)