Skip to content

Commit

Permalink
Add support for server version 1.4.x 1.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Jun 18, 2021
1 parent 7225d2c commit 13994cc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions BasicInfoAPI/src/main/api/IServerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ExtraDescr{
public String text;
public String color;
}
boolean isAvailable();
String getVersionName();
int getVersionProtocol();
int getMaxPlayer();
Expand Down
16 changes: 16 additions & 0 deletions BasicInfoAPI/src/main/conn/MinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MinecraftServer extends Thread implements IServerInfo {
private String host;
private int port=25565;
private Response response=null;
private boolean available=false;
public MinecraftServer(String host,int port)throws Exception {
socket=new Socket(host,port);
this.host=host;
Expand All @@ -38,6 +39,11 @@ public MinecraftServer(String host,int port)throws Exception {
new PacketSend(0).write(dataOutputStream);
try {
response = new Gson().fromJson(new PacketRecv(dataInputStream).popString(), Response.class);
if (response==null){
available=false;
throw new EOFException("Invalid server response.");
}
available=true;
}catch (EOFException e){//To change protocol.
socket=new Socket(host,port);
dataInputStream=new DataInputStream(socket.getInputStream());
Expand Down Expand Up @@ -67,6 +73,7 @@ public MinecraftServer(String host,int port)throws Exception {
(new String(bbase.pop(end),StandardCharsets.UTF_16BE));
response.players.max=Integer.parseInt
(new String(bbase.pop(end),StandardCharsets.UTF_16BE));
available=true;
}
}
}
Expand All @@ -80,6 +87,11 @@ private class ByteBase{
int index=0;
ByteBase(byte[] byteArr){
this.arr=byteArr;
// System.out.print("list:");
// for (byte b:byteArr){
// System.out.print(b+" ");
// }
// System.out.println();
}
public byte[] pop(byte[] end){
ArrayList<Byte> byteArrayList=new ArrayList<>();
Expand Down Expand Up @@ -136,6 +148,10 @@ static class version{
String favicon;
}

@Override
public boolean isAvailable(){
return available;
}

@Override
public String getVersionName() {
Expand Down
1 change: 1 addition & 0 deletions BasicInfoAPI/src/test/conn/MinecraftServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class MinecraftServerTest {
public static void main(String[] args)throws Exception {
MinecraftServer minecraftServer=new MinecraftServer("localhost",25565);
System.out.println("available:"+minecraftServer.isAvailable());
System.out.println("version:name:"+minecraftServer.getVersionName()+" protocol:"+minecraftServer.getVersionProtocol());
System.out.println("defaultDescription:color:"+minecraftServer.getDefaultDescriptionColor()+" text:"+minecraftServer.getDefaultDescriptionText());
IServerInfo.ExtraDescr[] extraDescrs=minecraftServer.getExtraDescription();
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ This repo contains several modules.Provides APIs for bot making or related proje

## BasicInfoAPI

Supports to get basic info of a Minecraft server.Using the official client's way to get info that can be listed in Minecraft client's server list.
Click the dir link to get further info.
Supports to get basic info of a Minecraft server.
Using the official client's way to get info that can be listed in Minecraft client's server list.
Click the dir link to get further info.
Supported server version:
1.17.x
1.16.x
1.15.x
1.14.x
1.13.x
1.12.x
1.11.x
1.10.x
1.9.x
1.8.x
1.7.x
1.6.x
1.4.x
1.5.x

Latest Release:0.1
Latest Release:0.2

0 comments on commit 13994cc

Please sign in to comment.