commit a076dca30ea19da313b8d17c7d30248653e1800f Author: NorbiPeti Date: Thu Mar 15 22:54:51 2018 +0100 Added some Patreon code And some ButtonWebsiteModule code diff --git a/PatreonPlugin.iml b/PatreonPlugin.iml new file mode 100644 index 0000000..1fee527 --- /dev/null +++ b/PatreonPlugin.iml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..84e5651 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + com.github.TBMCPlugins + PatreonPlugin + 1.0-SNAPSHOT + + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-shade-plugin + 2.4.2 + + + package + + shade + + + + + com.patreon:patreon + + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack + https://jitpack.io/ + + + + + org.spigotmc + spigot-api + 1.12.2-R0.1-SNAPSHOT + compile + + + com.github.tbmcplugins + ButtonWebsiteModule + master-SNAPSHOT + compile + + + com.github.TBMCPlugins.ButtonCore + ButtonCore + master-SNAPSHOT + compile + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..190ba68 --- /dev/null +++ b/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.github.TBMCPlugins + PatreonPlugin + 1.0-SNAPSHOT + + + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.2 + + + package + + shade + + + + + com.patreon:patreon + + + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack + https://jitpack.io/ + + + + + + com.patreon + patreon + 0.3.0 + + + org.spigotmc + spigot-api + 1.12.2-R0.1-SNAPSHOT + + + com.github.tbmcplugins + ButtonWebsiteModule + master-SNAPSHOT + + + com.github.TBMCPlugins.ButtonCore + ButtonCore + master-SNAPSHOT + + + org.projectlombok + lombok + 1.16.16 + + + \ No newline at end of file diff --git a/src/main/java/PatreonPage.java b/src/main/java/PatreonPage.java new file mode 100644 index 0000000..5f58572 --- /dev/null +++ b/src/main/java/PatreonPage.java @@ -0,0 +1,49 @@ +import buttondevteam.website.io.IOHelper; +import buttondevteam.website.io.Response; +import buttondevteam.website.page.Page; +import com.patreon.PatreonAPI; +import com.patreon.PatreonOAuth; +import com.sun.net.httpserver.HttpExchange; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.bukkit.configuration.file.FileConfiguration; + +import java.io.IOException; + +@RequiredArgsConstructor +public class PatreonPage extends Page { + private final FileConfiguration config; + + @Override + public String GetName() { + return "patreon"; + } + + @Override + public Response handlePage(HttpExchange httpExchange) { + val qkv = IOHelper.parseQueryString(httpExchange); + boolean connected = qkv.containsKey("code") && qkv.containsKey("state"); + try { + if (connected) { + String secret = config.getString("secret", null); + if (secret == null) + throw new RuntimeException("Cannot find secret in config file!"); + PatreonOAuth poac = new PatreonOAuth("zXFpLkmoTd9ex0RhdhNMoz42lLx4_okULp08EqBRcuGVnEn7e6Pq7zk-a2gMXqSX", secret, "https://server.figytuna.com/patreon"); + val tokens = poac.getTokens(qkv.get("code")); //TODO: Save user data, handle rewards + //TODO: Implement login page in BWM and add redirect param to it + /*String acctoken=config.getString("accesstoken", null); + if(acctoken==null) + throw new RuntimeException("Cannot find access token in config file!");*/ + PatreonAPI papi = new PatreonAPI(tokens.getAccessToken()); + try { + papi.fetchCampaigns().get().get(0).getPledges().get(0).getReward().getAmountCents(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return IOHelper.Redirect("https://tbmcplugins.github.io/patreon?connected=" + (connected ? "yess" : "noo"), httpExchange); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/PluginMain.java b/src/main/java/PluginMain.java new file mode 100644 index 0000000..a45ae29 --- /dev/null +++ b/src/main/java/PluginMain.java @@ -0,0 +1,9 @@ +import buttondevteam.website.ButtonWebsiteModule; +import org.bukkit.plugin.java.JavaPlugin; + +public class PluginMain extends JavaPlugin { + @Override + public void onEnable() { + ButtonWebsiteModule.addPage(new PatreonPage(getConfig())); + } +}