-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82ec96f
commit 6a6873d
Showing
12 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<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>cn.xiaopangxie732</groupId> | ||
<artifactId>mojang-api</artifactId> | ||
<version>0.0.1</version> | ||
<name>Mojang Public API in Java</name> | ||
<description>Mojang Public API Java implementation</description> | ||
<url>https://github.com/XiaoPangxie732/MojangAPI-in-Java</url> | ||
<packaging>jar</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5.7</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>3.0.1</version> | ||
<configuration> | ||
<encoding>GBK</encoding> | ||
<docencoding>GBK</docencoding> | ||
<show>private</show> | ||
<locale>en_US</locale> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cn.xiaopangxie732.mojang_api; | ||
|
||
import java.util.Properties; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import cn.xiaopangxie732.mojang_api.exceptions.InvalidServerException; | ||
import cn.xiaopangxie732.mojang_api.status.StatusServer; | ||
import cn.xiaopangxie732.mojang_api.status.StatusType; | ||
import cn.xiaopangxie732.mojang_api.util.Net; | ||
|
||
/** | ||
* Use this class to check Mojang's server status | ||
* @author XiaoPangxie732 | ||
*/ | ||
public class Status { | ||
private final String url = "https://status.mojang.com/check"; | ||
private String response; | ||
private Gson json = new Gson(); | ||
public Status() { | ||
response = Net.getConnection(url); | ||
} | ||
/** | ||
* To check server status | ||
* @throws InvalidServerException When the server is invalid or <code>null</code>. | ||
* @param server Which server needs to check the status. | ||
* @return The status of this server. | ||
*/ | ||
public StatusType getStatus(StatusServer server) throws InvalidServerException { | ||
if(server == null) throw new InvalidServerException("null"); | ||
Properties[] result = json.fromJson(response, Properties[].class); | ||
String value = result[server.ordinal()].getProperty(server.toString()); | ||
switch (value) { | ||
case "green": | ||
return StatusType.GREEN; | ||
case "yellow": | ||
return StatusType.YELLOW; | ||
case "red": | ||
return StatusType.RED; | ||
} | ||
return StatusType.COULD_NOT_CONNECT; | ||
} | ||
/** | ||
* To flush Mojang's server status. | ||
*/ | ||
public void flush() { | ||
response = Net.getConnection(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cn.xiaopangxie732.mojang_api; | ||
|
||
/** | ||
* Incomplete | ||
* @author XiaoPangxie732 | ||
*/ | ||
public class UUIDName { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.xiaopangxie732.mojang_api; | ||
|
||
/** | ||
* Incomplete | ||
* @author XiaoPangxie732 | ||
*/ | ||
public class UserName { | ||
|
||
// public | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/cn/xiaopangxie732/mojang_api/exceptions/InvalidServerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cn.xiaopangxie732.mojang_api.exceptions; | ||
|
||
/** | ||
* Thrown when server is invalid or <code>null</code>. | ||
* @author XiaoPangxie732 | ||
*/ | ||
public class InvalidServerException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = -6624733586870154037L; | ||
|
||
public InvalidServerException(String cause) { | ||
super(cause); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/cn/xiaopangxie732/mojang_api/exceptions/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* This package stored all exception classes. | ||
* @author XiaoPangxie732 | ||
*/ | ||
package cn.xiaopangxie732.mojang_api.exceptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* The MojangAPI main package | ||
* | ||
* @author XiaoPangxie732 | ||
*/ | ||
package cn.xiaopangxie732.mojang_api; |
26 changes: 26 additions & 0 deletions
26
src/main/java/cn/xiaopangxie732/mojang_api/status/StatusServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cn.xiaopangxie732.mojang_api.status; | ||
|
||
/** | ||
* This class lists all the servers that can check the status. | ||
* @author XiaoPangxie732 | ||
*/ | ||
public enum StatusServer { | ||
MINECRAFT_NET, | ||
SESSION_MINECRAFT_NET, | ||
ACCOUNT_MOJANG_COM, | ||
AUTHSERVER_MOJANG_COM, | ||
SESSIONSERVER_MOJANG_COM, | ||
API_MOJANG_COM, | ||
TEXTURES_MINECRAFT_NET, | ||
MOJANG_COM; | ||
|
||
/** | ||
* The toString() method of this class.<br> | ||
* @return E.g MINECRAFT_NET toString() is minecraft.net | ||
* @author XiaoPangxie732 | ||
*/ | ||
@Override | ||
public String toString() { | ||
return name().toLowerCase().replace("_", "."); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/cn/xiaopangxie732/mojang_api/status/StatusType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cn.xiaopangxie732.mojang_api.status; | ||
|
||
/** | ||
* This class lists all status type. | ||
* @author XiaoPangxie732 | ||
*/ | ||
public enum StatusType { | ||
GREEN, | ||
YELLOW, | ||
RED, | ||
COULD_NOT_CONNECT; | ||
|
||
/** | ||
* The StatusType toString() method. | ||
* @return E.g GREEN toString() is green. | ||
* @author XiaoPangxie732 | ||
*/ | ||
@Override | ||
public String toString() { | ||
return name().toLowerCase(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/cn/xiaopangxie732/mojang_api/status/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* The package about Status. | ||
* @author XiaoPangxie732 | ||
*/ | ||
package cn.xiaopangxie732.mojang_api.status; |
5 changes: 5 additions & 0 deletions
5
src/main/java/cn/xiaopangxie732/mojang_api/username/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* The package about UserName. | ||
* @author XiaoPangxie732 | ||
*/ | ||
package cn.xiaopangxie732.mojang_api.username; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cn.xiaopangxie732.mojang_api.util; | ||
|
||
import java.net.URL; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
public class Net { | ||
public static String getConnection(String url) { | ||
String response = null; | ||
try { | ||
HttpGet get = new HttpGet(new URL(url).toURI()); | ||
HttpResponse re = HttpClientBuilder.create().build().execute(get); | ||
response = EntityUtils.toString(re.getEntity()); | ||
get.releaseConnection(); | ||
} catch (Exception e) {e.printStackTrace();} | ||
return response; | ||
} | ||
} |