Skip to content

Commit d226005

Browse files
author
EazyFTW
committed
Fixed verify command not allowing mentions.
1 parent f0bf289 commit d226005

32 files changed

+1631
-5
lines changed

SpigotAPI/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.DS_Store
2+
*.iml
3+
.idea/
4+
.gradle/
5+
out/
6+
build/
7+
build.properties

SpigotAPI/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SpigotAPI
2+
Standalone Web API for retrieving Information off of SpigotMC!
3+
4+
## How To Host This API
5+
6+
Script: ``java -jar SpigotAPI.jar <Spigot Username> <Spigot Password> <API Token>``
7+
8+
The API Token should be a secure random string that will be needed for accessing this api.
9+
10+
## More Information
11+
12+
This API will allow you to get information about all of the buyers from each of your plugins, information about all the updates of each of your plugins, every single review posted on any of your plugins, and info about all of your resources.

SpigotAPI/build.gradle

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
apply plugin: 'java'
2+
apply plugin: 'com.github.johnrengelman.shadow'
3+
apply plugin: 'org.hidetake.ssh'
4+
5+
group = "me.TechsCode"
6+
version = 1.1
7+
8+
sourceCompatibility = 1.8
9+
targetCompatibility = 1.8
10+
11+
repositories {
12+
maven { url 'https://jitpack.io' }
13+
14+
jcenter()
15+
mavenLocal()
16+
mavenCentral()
17+
}
18+
19+
dependencies {
20+
// Server
21+
shadow group: 'commons-io', name: 'commons-io', version: '2.6'
22+
shadow "com.googlecode.json-simple:json-simple:1.1.1"
23+
24+
// Client
25+
shadow "org.jsoup:jsoup:1.8.3"
26+
shadow "net.sourceforge.htmlunit:htmlunit:2.29"
27+
shadow "org.nanohttpd:nanohttpd:2.3.1"
28+
}
29+
30+
def props = new Properties()
31+
def file = file("build.properties")
32+
def hasUploadSettings = file.exists();
33+
34+
if(hasUploadSettings){
35+
file.withInputStream { props.load(it) }
36+
}
37+
38+
ssh.remotes {
39+
server {
40+
host = hasUploadSettings ? props.getProperty("host") : ""
41+
port = hasUploadSettings ? Integer.valueOf(props.getProperty("port")) : 22
42+
user = hasUploadSettings ? props.getProperty("user") : ""
43+
password = hasUploadSettings ? props.getProperty("password") : ""
44+
}
45+
}
46+
47+
ssh.settings {
48+
knownHosts = allowAnyHosts
49+
dryRun = false
50+
}
51+
52+
task upload {
53+
if(!hasUploadSettings) return;
54+
55+
doLast {
56+
ssh.run {
57+
session(ssh.remotes.server) {
58+
put from: files('build/SpigotAPI.jar'), into: props.getProperty("location")
59+
}
60+
}
61+
}
62+
}
63+
64+
65+
buildscript {
66+
repositories {
67+
jcenter()
68+
}
69+
dependencies {
70+
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
71+
classpath 'org.hidetake:gradle-ssh-plugin:2.10.1'
72+
}
73+
}
74+
75+
shadowJar {
76+
archiveName = 'SpigotAPI.jar'
77+
destinationDir = new File("build")
78+
79+
dependsOn 'build'
80+
configurations = [project.configurations.shadow]
81+
}
82+
83+
jar {
84+
manifest {
85+
attributes 'Class-Path': '/libs/a.jar'
86+
attributes 'Main-Class': 'me.TechsCode.SpigotAPI.server.SpigotAPIServer'
87+
}
88+
}
89+
90+
tasks.withType(JavaCompile) {
91+
options.encoding = 'UTF-8'
92+
}

SpigotAPI/build.properties.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SSH Credentials for direct uploading after compiling
2+
host=somehost.com
3+
port=22
4+
user=someuser
5+
password=somepassword
6+
7+
# Export Location on Server
8+
location=/path/to/folder
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package me.TechsCode.SpigotAPI.client;
2+
3+
import me.TechsCode.SpigotAPI.client.objects.*;
4+
import me.TechsCode.SpigotAPI.logging.Logger;
5+
import org.apache.commons.io.IOUtils;
6+
import org.json.simple.JSONArray;
7+
import org.json.simple.JSONObject;
8+
import org.json.simple.parser.JSONParser;
9+
10+
import java.net.URI;
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.stream.Collectors;
13+
import java.util.stream.IntStream;
14+
import java.util.stream.Stream;
15+
16+
public class APIScanner {
17+
18+
private SpigotAPIClient client;
19+
private String url;
20+
private String token;
21+
22+
private APIStatus status;
23+
24+
public APIScanner(SpigotAPIClient client, String url, String token) {
25+
this.client = client;
26+
this.url = url;
27+
this.token = token;
28+
this.status = APIStatus.WAITING;
29+
}
30+
31+
public Data retrieveData() {
32+
JSONObject data;
33+
34+
try {
35+
JSONParser parser = new JSONParser();
36+
String json = IOUtils.toString(new URI(url + "/?token=" + token), StandardCharsets.UTF_8);
37+
JSONObject root = (JSONObject) parser.parse(json);
38+
39+
String status = (String) root.get("status");
40+
if(!status.equalsIgnoreCase("success")){
41+
Logger.log("API returned error message:");
42+
System.out.println(root.get("message"));
43+
this.status = APIStatus.WAITING;
44+
return null;
45+
}
46+
data = (JSONObject) root.get("data");
47+
} catch (Exception e) {
48+
Logger.log("Could not reach SpigotAPI on " + url);
49+
this.status = APIStatus.OFF;
50+
return null;
51+
}
52+
53+
this.status = APIStatus.OK;
54+
55+
Resource[] resources = getChilds(data.get("resources")).map(item -> new Resource(client, item)).toArray(Resource[]::new);
56+
Purchase[] purchases = getChilds(data.get("purchases")).map(item -> new Purchase(client, item)).toArray(Purchase[]::new);
57+
Review[] reviews = getChilds(data.get("reviews")).map(item -> new Review(client, item)).toArray(Review[]::new);
58+
Update[] updates = getChilds(data.get("updates")).map(item -> new Update(client, item)).toArray(Update[]::new);
59+
60+
return new Data(System.currentTimeMillis(), resources, purchases, reviews, updates);
61+
}
62+
63+
private Stream<JSONObject> getChilds(Object object) {
64+
JSONArray jsonArray = (JSONArray) object;
65+
return IntStream.rangeClosed(0, jsonArray.size() - 1).mapToObj(i -> (JSONObject) jsonArray.get(i)).collect(Collectors.toList()).stream();
66+
}
67+
68+
public APIStatus getStatus() {
69+
return status;
70+
}
71+
72+
public enum APIStatus {
73+
OK("Online", "The api is currently running with no issues!"),
74+
WAITING("Gathering Info", "The api is currently gathering information. This usually takes around 5-10 mins."),
75+
OFF("Offline", "The api is offline and it cannot even fetch the url!");
76+
77+
private String name, description;
78+
79+
APIStatus(String name, String description) {
80+
this.name = name;
81+
this.description = description;
82+
}
83+
84+
public String getName() {
85+
return name;
86+
}
87+
88+
public String getDescription() {
89+
return description;
90+
}
91+
}
92+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.TechsCode.SpigotAPI.client;
2+
3+
import me.TechsCode.SpigotAPI.client.objects.Data;
4+
5+
import java.util.concurrent.TimeUnit;
6+
7+
public class DataManager extends Thread {
8+
9+
private static final long REFRESH_DELAY = TimeUnit.MINUTES.toMillis(15);
10+
private long timeout = 0;
11+
12+
private APIScanner apiEndpoint;
13+
private Data latest;
14+
15+
public DataManager(APIScanner apiEndpoint) {
16+
this.apiEndpoint = apiEndpoint;
17+
this.latest = null;
18+
19+
start();
20+
}
21+
22+
public Data getData(){
23+
return latest;
24+
}
25+
}
26+
27+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package me.TechsCode.SpigotAPI.client;
2+
3+
import me.TechsCode.SpigotAPI.client.collections.PurchaseCollection;
4+
import me.TechsCode.SpigotAPI.client.collections.ResourceCollection;
5+
import me.TechsCode.SpigotAPI.client.collections.ReviewCollection;
6+
import me.TechsCode.SpigotAPI.client.collections.UpdateCollection;
7+
import me.TechsCode.SpigotAPI.client.objects.*;
8+
import me.TechsCode.SpigotAPI.logging.ConsoleColor;
9+
import me.TechsCode.SpigotAPI.logging.Logger;
10+
11+
import java.util.concurrent.TimeUnit;
12+
13+
public class SpigotAPIClient extends Thread {
14+
15+
private static final long REFRESH_DELAY = TimeUnit.MINUTES.toMillis(1);
16+
private long timeout = 0;
17+
18+
private APIScanner scanner;
19+
private Data latest;
20+
21+
private APIScanner.APIStatus cacheStatus;
22+
23+
public SpigotAPIClient(String url, String token){
24+
Logger.log("Connecting to SpigotAPI instance on " + url);
25+
scanner = new APIScanner(this, url, token);
26+
27+
cacheStatus = APIScanner.APIStatus.WAITING;
28+
29+
retrieveData();
30+
start();
31+
}
32+
33+
private void retrieveData() {
34+
Data latest2 = scanner.retrieveData();
35+
36+
if(latest2 == null) {
37+
Logger.log(ConsoleColor.RED + " Could not retrieve new data.. Waiting 5 minutes.. (NEW: Saving old data)");
38+
timeout = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5);
39+
if(latest == null) cacheStatus = scanner.getStatus();
40+
} else {
41+
latest = latest2;
42+
cacheStatus = APIScanner.APIStatus.OK;
43+
}
44+
}
45+
46+
@Override
47+
public void run() {
48+
while (true) {
49+
if(timeout != 0 && timeout > System.currentTimeMillis()) continue;
50+
51+
if(latest == null || (System.currentTimeMillis() - latest.getRetrievedTime()) > REFRESH_DELAY) {
52+
retrieveData();
53+
}
54+
}
55+
}
56+
57+
public ResourceCollection getResources() {
58+
return new ResourceCollection(isAvailable() ? latest.getResources() : new Resource[0]);
59+
}
60+
61+
public PurchaseCollection getPurchases() {
62+
return new PurchaseCollection(isAvailable() ? latest.getPurchases() : new Purchase[0]);
63+
}
64+
65+
public ReviewCollection getReviews() {
66+
return new ReviewCollection(isAvailable() ? latest.getReviews() : new Review[0]);
67+
}
68+
69+
public UpdateCollection getUpdates() {
70+
return new UpdateCollection(isAvailable() ? latest.getUpdates() : new Update[0]);
71+
}
72+
73+
public boolean isAvailable() {
74+
if(latest == null) return false;
75+
return latest.getPurchases() != null;
76+
}
77+
78+
public APIScanner.APIStatus getStatus() {
79+
return scanner.getStatus();
80+
}
81+
82+
public APIScanner.APIStatus getCacheStatus() {
83+
return cacheStatus;
84+
}
85+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.TechsCode.SpigotAPI.client.collections;
2+
3+
import me.TechsCode.SpigotAPI.client.objects.Purchase;
4+
import me.TechsCode.SpigotAPI.client.objects.Resource;
5+
6+
import java.util.Arrays;
7+
import java.util.stream.Stream;
8+
9+
public class PurchaseCollection {
10+
11+
private Purchase[] array;
12+
13+
public PurchaseCollection(Purchase[] array) {
14+
this.array = array;
15+
}
16+
17+
public PurchaseCollection resource(Resource resource){
18+
return resourceId(resource.getId());
19+
}
20+
21+
public PurchaseCollection resourceName(String resourceName){
22+
return new PurchaseCollection(getStream().filter(x -> x.getResourceName().equalsIgnoreCase(resourceName)).toArray(Purchase[]::new));
23+
}
24+
25+
public PurchaseCollection resourceId(String resourceId){
26+
return new PurchaseCollection(getStream().filter(x -> x.getResourceId().equalsIgnoreCase(resourceId)).toArray(Purchase[]::new));
27+
}
28+
29+
public PurchaseCollection username(String username){
30+
return new PurchaseCollection(getStream().filter(x -> x.getUsername().equalsIgnoreCase(username)).toArray(Purchase[]::new));
31+
}
32+
33+
public PurchaseCollection userId(String userId){
34+
return new PurchaseCollection(getStream().filter(x -> x.getUserId().equalsIgnoreCase(userId)).toArray(Purchase[]::new));
35+
}
36+
37+
public PurchaseCollection older(long time){
38+
return new PurchaseCollection(getStream().filter(x -> x.getTime().getUnixTime() > time).toArray(Purchase[]::new));
39+
}
40+
41+
public PurchaseCollection newer(long time){
42+
return new PurchaseCollection(getStream().filter(x -> x.getTime().getUnixTime() < time).toArray(Purchase[]::new));
43+
}
44+
45+
public Stream<Purchase> getStream(){
46+
return Arrays.stream(array);
47+
}
48+
49+
public Purchase[] get(){
50+
return array;
51+
}
52+
53+
public Purchase first(){
54+
return array[0];
55+
}
56+
57+
public int size(){
58+
return array.length;
59+
}
60+
}

0 commit comments

Comments
 (0)