Skip to content

Commit

Permalink
Add README of module BasicInfoAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Jun 16, 2021
1 parent 952983d commit fa33d29
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
48 changes: 48 additions & 0 deletions BasicInfoAPI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# BasicInfoAPI
[README](README.md) | [中文文档](README_cn.md)

## Version

Latest Release:0.1,check release page.

## Abstract

Import this API as a jar lib.Provide interfaces to get information,such as server's
version,description(MOTD),player online list and so on that official client can get.

## Usage

```java
/**
* Create a MinecraftServer object connected with the minecraft server running on port 25565 on host server.address.
* Caution:this method will try to connect to the determined server and get message that includes basic info,so this method
* will not return until receive the message.
*/
MinecraftServer minecraftServer=new MinecraftServer("server.address",25565);
/**
* Call provided methods from interface to get specific info.
*/
System.out.println("version:name:"+minecraftServer.getVersionName()+" protocol:"+minecraftServer.getVersionProtocol());
System.out.println("defaultDescription:color:"+minecraftServer.getDefaultDescriptionColor()+" text:"+minecraftServer.getDefaultDescriptionText());
/**
* Get the list of extra description includes text and color.
* If your server does not have extra description(as usual),you can simply use getDefaultDescriptionColor() and getDefaultDescriptionText().
*/
IServerInfo.ExtraDescr[] extraDescrs=minecraftServer.getExtraDescription();
for (IServerInfo.ExtraDescr extraDescr:extraDescrs){
System.out.println("extraDescription:color:"+extraDescr.color+" text:"+extraDescr.text);
}
System.out.println("players:max:"+minecraftServer.getMaxPlayer()+" online:"+minecraftServer.getOnlinePlayer());
/**
* Get online player list.
*/
IServerInfo.Player[] players=minecraftServer.getPlayerList();
for (IServerInfo.Player p:players){
System.out.println("player:name:"+p.name+" id:"+p.id);
}
/**
* Get server's icon(favicon) described in a Base64 way.
* Caution:sometime the packet with a very big Base64 data from server will cause a internal exception,you should try again.
*/
System.out.println("favicon:"+minecraftServer.getFavicon());
```
50 changes: 50 additions & 0 deletions BasicInfoAPI/README_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# BasicInfoAPI
[README](README.md) | [中文文档](README_cn.md)

## 版本

最近的发行版:0.1,请参阅 Release 页面.

## 摘要

将此API以jar库的形式引入项目。此API提供了获取信息的接口,这些信息包括 服务器的版本 描述(MOTD) 在线玩家列表等能被官方客户端获取并展示在服务器列表的信息。

## 用法

```java
/**
* 创建一个连接到运行在主机server.address上25565端口的Minecraft服务器的MinecraftServer对象
* 注意:此方法将会尝试连接到指定的服务器并获取包含基本信息的消息,因此此方法在获取到消息前不会返回,这是一个堵塞的方法
*/
MinecraftServer minecraftServer=new MinecraftServer("server.address",25565);
/**
* 接下来,调用由接口提供的方法以获取特定的信息
*/
System.out.println("version:name:"+minecraftServer.getVersionName()+" protocol:"+minecraftServer.getVersionProtocol());
System.out.println("defaultDescription:color:"+minecraftServer.getDefaultDescriptionColor()+" text:"+minecraftServer.getDefaultDescriptionText());
/**
* 获取额外描述的列表,额外描述中包含了颜色和文字
* 如果你的服务器不含有额外描述(通常来说是这样),你可以简单地调用getDefaultDescriptionColor() 和 getDefaultDescriptionText()方法
* 而不需要检查额外描述(extra description)
*/
IServerInfo.ExtraDescr[] extraDescrs=minecraftServer.getExtraDescription();
for (IServerInfo.ExtraDescr extraDescr:extraDescrs){
System.out.println("extraDescription:color:"+extraDescr.color+" text:"+extraDescr.text);
}
/**
* 获取基本玩家信息
*/
System.out.println("players:max:"+minecraftServer.getMaxPlayer()+" online:"+minecraftServer.getOnlinePlayer());
/**
* 获取在线玩家列表
*/
IServerInfo.Player[] players=minecraftServer.getPlayerList();
for (IServerInfo.Player p:players){
System.out.println("player:name:"+p.name+" id:"+p.id);
}
/**
* 获取以Base64编码的服务器图标(favicon)
* 注意:有些时候某个服务器包含了巨量的Base64编码的favicon,这会引起一些内部错误,请重新调用
*/
System.out.println("favicon:"+minecraftServer.getFavicon());
```

0 comments on commit fa33d29

Please sign in to comment.