From 13050a81cdea9818dce56f190d8c7c6775f8d8ff Mon Sep 17 00:00:00 2001 From: Alexander Meech Date: Tue, 18 Oct 2016 20:49:54 -0400 Subject: [PATCH] Update remote staff fetcher to translate... (#623) * Update remote staff fetcher to translate... ...color codes, use proper link, and use multiline entry management * Implement maven shading for external libraries and set up remote staff fetcher to appropriately handle html pages * Use maven instead of ant with travis --- .travis.yml | 2 +- dependency-reduced-pom.xml | 223 ++++++++++++++++++ pom.xml | 27 +++ .../projectkorra/command/WhoCommand.java | 48 ++-- 4 files changed, 279 insertions(+), 21 deletions(-) create mode 100644 dependency-reduced-pom.xml diff --git a/.travis.yml b/.travis.yml index 5f1deb98..5db461e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: java -script: ant main +script: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V sudo: false jdk: - oraclejdk7 diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 00000000..01cd3227 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,223 @@ + + + 4.0.0 + com.projectkorra + projectkorra + don't matter + + ${project.basedir}/src + + + true + ${basedir}/src + + plugin.yml + + + + ${project.name} + + + maven-shade-plugin + 2.3 + + + package + + shade + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + worldedit-worldguard-repo + http://maven.sk89q.com/repo/ + + + + + org.spigotmc + spigot-api + 1.10.2-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + gson + com.google.code.gson + + + ebean + org.avaje + + + snakeyaml + org.yaml + + + bungeecord-chat + net.md-5 + + + + + com.sk89q + worldguard + 6.1.1-SNAPSHOT + provided + + + worldedit + com.sk89q + + + bukkit-classloader-check + com.sk89q.spigot + + + bukkit + org.bukkit + + + commandbook + com.sk89q + + + jsr305 + com.google.code.findbugs + + + + + com.sk89q.worldedit + worldedit-bukkit + 6.1.4-SNAPSHOT + provided + + + dummypermscompat + com.sk89q + + + worldedit-core + com.sk89q.worldedit + + + bukkit + org.bukkit + + + + + com.google.guava + guava + 19.0 + provided + + + com.googlecode.json-simple + json-simple + 1.1.1 + provided + + + junit + junit + + + + + me.ryanhamshire + GriefPrevention + 10.5.3 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/GriefPrevention 10.5.3.jar + + + com.griefcraft + lwc + 4.5.0-SNAPSHOT + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/LWC.jar + + + com.massivecraft + massivecore + 2.7.5 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/MassiveCore 2.7.5.jar + + + fr.neatmonster + nocheatplus + 3.11.0-RC-sMD5NET-b739 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/NoCheatPlus.jar + + + com.palmergames.bukkit + towny + 0.89.2.0 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/Towny.jar + + + com.bekvon.bukkit + residence + 4.0.0.4 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/Residence4.0.0.4.jar + + + com.projectkorra + spirits + 1.0.0 PRIVATE PREALPHA + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/ProjectKorraSpirits.jar + + + com.projectkorra + rpg + 1.0.2 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/ProjectKorraRPG.jar + + + com.projectkorra + items + 1.2.0 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/ProjectKorraItems.jar + + + net.sacredlabyrinth.Phaed + PreciousStones + 9.7.1-SNAPSHOT + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/PreciousStones 9.7.1.jar + + + com.massivecraft + factions + 2.7.5 + system + C:\Users\alexj\Desktop\ProjectKorra\code\ProjectKorra/lib/Factions 2.7.5.jar + + + + 1.7 + 1.7 + + + diff --git a/pom.xml b/pom.xml index 9441091f..749a2fe0 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,23 @@ + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + + + package + + shade + + + + + @@ -50,24 +67,34 @@ com.sk89q worldguard 6.1.1-SNAPSHOT + provided com.sk89q.worldedit worldedit-bukkit 6.1.4-SNAPSHOT + provided com.google.guava guava 19.0 + provided com.googlecode.json-simple json-simple 1.1.1 + provided + + + org.jsoup + jsoup + 1.9.2 + me.ryanhamshire GriefPrevention diff --git a/src/com/projectkorra/projectkorra/command/WhoCommand.java b/src/com/projectkorra/projectkorra/command/WhoCommand.java index 71d12d35..262c6e0e 100644 --- a/src/com/projectkorra/projectkorra/command/WhoCommand.java +++ b/src/com/projectkorra/projectkorra/command/WhoCommand.java @@ -1,15 +1,17 @@ package com.projectkorra.projectkorra.command; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -17,6 +19,8 @@ import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.Element; @@ -52,29 +56,33 @@ public class WhoCommand extends PKCommand { { public void run() { - try { + try + { // Create a URL for the desired page - URL url = new URL("http://www.projectkorra.com/internals/staff.html"); - + URLConnection url = new URL("http://www.projectkorra.com/staff.html").openConnection(); + url.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); + // Read all the text returned by the server - BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); - String unparsed = in.readLine(); // Read first line - if (unparsed != null) + BufferedReader in = new BufferedReader(new InputStreamReader(url.getInputStream(), Charset.forName("UTF-8"))); + String unparsed; + while ((unparsed = in.readLine()) != null) { - String[] staffUUIDS = unparsed.split("\\|"); - for (String s : staffUUIDS) + Document doc = Jsoup.parse(unparsed); + String parsed = doc.body().text(); + String[] staffEntry = parsed.split("/"); + if (staffEntry.length >= 2) { - String[] parts = s.split("/"); - if (parts.length == 2) - { - staff.put(parts[0], parts[1]); - } + staff.put(staffEntry[0], ChatColor.translateAlternateColorCodes('&', staffEntry[1])); } } in.close(); - } catch (MalformedURLException e) { + } + catch (MalformedURLException e) + { e.printStackTrace(); - } catch (IOException e) { + } + catch (IOException e) + { e.printStackTrace(); } }