Added some Patreon code

And some ButtonWebsiteModule code
This commit is contained in:
Norbi Peti 2018-03-15 22:54:51 +01:00
commit a076dca30e
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 254 additions and 0 deletions

44
PatreonPlugin.iml Normal file
View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.patreon:patreon:0.3.0" level="project" />
<orderEntry type="library" name="Maven: com.github.jasminb:jsonapi-converter:0.8" level="project" />
<orderEntry type="library" name="Maven: com.squareup.retrofit2:retrofit:2.1.0" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.3.0" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.8.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.1" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.10.3" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.2.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.2.2" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.2" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
<orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.tbmcplugins:ButtonWebsiteModule:master-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.TBMCPlugins.ButtonCore:ButtonCore:master-v1.0-gc1751b8-228" level="project" />
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
</component>
</module>

View file

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.TBMCPlugins</groupId>
<artifactId>PatreonPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.patreon:patreon</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>jitpack</id>
<url>https://jitpack.io/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.tbmcplugins</groupId>
<artifactId>ButtonWebsiteModule</artifactId>
<version>master-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
<artifactId>ButtonCore</artifactId>
<version>master-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

82
pom.xml Normal file
View file

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.TBMCPlugins</groupId>
<artifactId>PatreonPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.patreon:patreon</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>jitpack</id>
<url>https://jitpack.io/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.patreon</groupId>
<artifactId>patreon</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.tbmcplugins</groupId>
<artifactId>ButtonWebsiteModule</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
<artifactId>ButtonCore</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
</dependency>
</dependencies>
</project>

View file

@ -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);
}
}
}

View file

@ -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()));
}
}