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) - [ ] 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 the code that loads server into a section (duplicated at SectionManager and ServerSection)
- [ ] Unify some of the code used in the FallbackCommand and SectionCommand - [ ] 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 - [ ] (!) 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 - [ ] (!) 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 - [ ] 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.google.common.io.CharStreams;
import com.jaimemartz.playerbalancer.PlayerBalancer; import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.utils.GuestPaste; 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.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@ -20,13 +21,13 @@ import java.util.function.BiConsumer;
public enum PasteHelper { public enum PasteHelper {
PLUGIN((sender, url) -> { PLUGIN((sender, url) -> {
if (sender instanceof ProxiedPlayer) { 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())) .event(new ClickEvent(ClickEvent.Action.OPEN_URL, url.toString()))
.color(ChatColor.GREEN) .color(ChatColor.GREEN)
.create() .create()
); );
} else { } else {
sender.sendMessage(new ComponentBuilder("Plugin configuration link: " + url.toString()).create()); sender.sendMessage(new ComponentBuilder("PlayerBalancer configuration link: " + url.toString()).create());
} }
}) { }) {
@Override @Override
@ -37,7 +38,7 @@ public enum PasteHelper {
String content = CharStreams.toString(reader); String content = CharStreams.toString(reader);
GuestPaste paste = new GuestPaste("e3ff18d8fb001a3ece08ae0d7d4a87bd", content); 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("{name}", plugin.getDescription().getName())
.replace("{version}", plugin.getDescription().getVersion()) .replace("{version}", plugin.getDescription().getVersion())
.replace("{bungee_version}", plugin.getProxy().getVersion()) .replace("{bungee_version}", plugin.getProxy().getVersion())
@ -52,6 +53,7 @@ public enum PasteHelper {
} }
} }
}, },
BUNGEE((sender, url) -> { BUNGEE((sender, url) -> {
if (sender instanceof ProxiedPlayer) { if (sender instanceof ProxiedPlayer) {
sender.sendMessage(new ComponentBuilder("Click me for the BungeeCord configuration") 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}", "?.?.?.?"); 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); GuestPaste paste = new GuestPaste("e3ff18d8fb001a3ece08ae0d7d4a87bd", content);
paste.setName("{name} ({version}) Configuration" paste.setName("{name} ({version})"
.replace("{name}", plugin.getProxy().getName()) .replace("{name}", plugin.getProxy().getName())
.replace("{version}", plugin.getProxy().getVersion()) .replace("{version}", plugin.getProxy().getVersion())
); );
@ -105,7 +107,7 @@ public enum PasteHelper {
task = plugin.getProxy().getScheduler().schedule(plugin, () -> { task = plugin.getProxy().getScheduler().schedule(plugin, () -> {
url = null; url = null;
}, 5, TimeUnit.MINUTES); }, 5, TimeUnit.MINUTES);
} catch (GuestPaste.PasteException e) { } catch (PasteException e) {
sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage()) sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage())
.color(ChatColor.RED) .color(ChatColor.RED)
.create() .create()

View File

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