Little OCD changes

This commit is contained in:
Jaime Martinez Rincon 2017-08-09 03:41:53 +02:00
parent 3a3aa2b348
commit 4e4289c877
3 changed files with 23 additions and 24 deletions

View File

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

View File

@ -3,6 +3,7 @@ package com.jaimemartz.playerbalancer.manager;
import com.google.common.io.CharStreams;
import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.utils.GuestPaste;
import com.jaimemartz.playerbalancer.utils.GuestPaste.PasteException;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent;
@ -20,13 +21,13 @@ import java.util.function.BiConsumer;
public enum PasteHelper {
PLUGIN((sender, url) -> {
if (sender instanceof ProxiedPlayer) {
sender.sendMessage(new ComponentBuilder("Click me for the plugin configuration")
sender.sendMessage(new ComponentBuilder("Click me for the PlayerBalancer configuration")
.event(new ClickEvent(ClickEvent.Action.OPEN_URL, url.toString()))
.color(ChatColor.GREEN)
.create()
);
} else {
sender.sendMessage(new ComponentBuilder("Plugin configuration link: " + url.toString()).create());
sender.sendMessage(new ComponentBuilder("PlayerBalancer configuration link: " + url.toString()).create());
}
}) {
@Override
@ -37,7 +38,7 @@ public enum PasteHelper {
String content = CharStreams.toString(reader);
GuestPaste paste = new GuestPaste("e3ff18d8fb001a3ece08ae0d7d4a87bd", content);
paste.setName("{name} ({version} on {bungee_version}) Configuration"
paste.setName("{name} ({version} on {bungee_version})"
.replace("{name}", plugin.getDescription().getName())
.replace("{version}", plugin.getDescription().getVersion())
.replace("{bungee_version}", plugin.getProxy().getVersion())
@ -52,6 +53,7 @@ public enum PasteHelper {
}
}
},
BUNGEE((sender, url) -> {
if (sender instanceof ProxiedPlayer) {
sender.sendMessage(new ComponentBuilder("Click me for the BungeeCord configuration")
@ -72,7 +74,7 @@ public enum PasteHelper {
content = content.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "?.?.?.?");
GuestPaste paste = new GuestPaste("e3ff18d8fb001a3ece08ae0d7d4a87bd", content);
paste.setName("{name} ({version}) Configuration"
paste.setName("{name} ({version})"
.replace("{name}", plugin.getProxy().getName())
.replace("{version}", plugin.getProxy().getVersion())
);
@ -105,7 +107,7 @@ public enum PasteHelper {
task = plugin.getProxy().getScheduler().schedule(plugin, () -> {
url = null;
}, 5, TimeUnit.MINUTES);
} catch (GuestPaste.PasteException e) {
} catch (PasteException e) {
sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage())
.color(ChatColor.RED)
.create()

View File

@ -19,10 +19,10 @@ public class GuestPaste {
private final String key;
private final String code;
private String name;
private String format;
private Expiration expiration;
private Exposure exposure;
private String name = null;
private String format = null;
private Expiration expiration = null;
private Exposure exposure = null;
public GuestPaste(String key, String code) {
this.key = key;
@ -50,11 +50,11 @@ public class GuestPaste {
}
if (expiration != null) {
params.add(new SimpleEntry<>("api_paste_expire_date", expiration.getValue()));
params.add(new SimpleEntry<>("api_paste_expire_date", expiration.value));
}
if (exposure != null) {
params.add(new SimpleEntry<>("api_paste_private", String.valueOf(exposure.getValue())));
params.add(new SimpleEntry<>("api_paste_private", String.valueOf(exposure.value)));
}
StringBuilder output = new StringBuilder();
@ -75,20 +75,18 @@ public class GuestPaste {
int status = con.getResponseCode();
if (status >= 200 && status < 300) {
try (InputStreamReader isr = new InputStreamReader(con.getInputStream())) {
try (BufferedReader br = new BufferedReader(isr)) {
String inputLine;
StringBuilder response = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
try {
return new URL(response.toString());
} catch (MalformedURLException e) {
throw new PasteException("Pastebin error: " + response.toString());
}
try {
return new URL(response.toString());
} catch (MalformedURLException e) {
throw new PasteException(response.toString());
}
}
} else {