Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nexiesy committed Oct 5, 2020
1 parent 4592c90 commit d664e1a
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PSIA.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
41 changes: 41 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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>net.nexiesy</groupId>
<artifactId>PSIA</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>


</project>
67 changes: 67 additions & 0 deletions src/main/java/net/nexiesy/PSIA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package net.nexiesy;


import lombok.Getter;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class PSIA {

@Getter
public PSIAServer server;
public PSIA(String url){
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet getRequest = new HttpGet(url);
HttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(getRequest);
} catch (IOException e) {
e.printStackTrace();
}
String content = null;
try {
assert httpResponse != null;
BufferedReader rd = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
content = result.toString();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}

String information = getInformationHtml(content);
List<String> players = Arrays.asList(information.split("Online Players")[1].split("FIND")[0].split(", "));
server = format(information.split("About")[3].split("Registered")[0], information.split("Statistics")[2].split("Share")[0], players);
}

public PSIAServer format(String about, String stats, List players){
String address = about.split("Address")[1].split("Status")[0].split("Hostname")[0].replace(" ", "");
String hostname = about.split("Hostname")[1].split("Status")[0].replace(" ", "");
String status = about.split("Status")[1].split("Players")[0].replace(" ", "");
String oplayers = about.replace("Hostname"+hostname, "").split("Players")[1].split("Location")[0].replace(" ", "");
String location = about.split("Location")[1].split("Version")[0].replace(" ", "");
String version = about.split("Version")[1].split("Website")[0].replace(" ", "");
String website = about.split("Website")[1].replace(" ", "");

String[] datas = stats.split(" ");
return new PSIAServer(address, hostname, status, oplayers, location, version, website, datas[2], Integer.parseInt(datas[4]), Integer.parseInt(datas[6]), Integer.parseInt(datas[8]), Integer.parseInt(datas[10]), Integer.parseInt(datas[12]), players);
}

private String getInformationHtml(String content){
Elements information = Jsoup.parse(content).getAllElements();
return information.get(1).text();
}
}
38 changes: 38 additions & 0 deletions src/main/java/net/nexiesy/PSIAServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.nexiesy;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@AllArgsConstructor
public class PSIAServer {
@Getter
private String address;
@Getter
private String hostname;
@Getter
private String status;
@Getter
private String players;
@Getter
private String location;
@Getter
private String version;
@Getter
private String website;
@Getter
private String uptime;
@Getter
private int vote;
@Getter
private int rank;
@Getter
private int score;
@Getter
private int favorited;
@Getter
private int discussion;
@Getter
private List<String> allPlayers;
}

0 comments on commit d664e1a

Please sign in to comment.