Skip to content

Commit

Permalink
Fix bug:NullPointerException bug when getting info
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Jun 16, 2021
1 parent fa33d29 commit 834ccf6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions BasicInfoAPI/src/main/conn/MinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ public int getOnlinePlayer() {

@Override
public Player[] getPlayerList() {
int len=response.players.sample.length;
Player[] players=new Player[len];
for (int i=0;i<len;i++){
players[i]=new Player();
players[i].name=response.players.sample[i].name;
players[i].id=response.players.sample[i].id;
if (response.players.sample!=null) {
int len = response.players.sample.length;
Player[] players = new Player[len];
for (int i = 0; i < len; i++) {
players[i] = new Player();
players[i].name = response.players.sample[i].name;
players[i].id = response.players.sample[i].id;
}
return players;
}else {
return new Player[0];
}
return players;
}

@Override
Expand All @@ -107,13 +111,17 @@ public String getDefaultDescriptionColor(){
}
@Override
public ExtraDescr[] getExtraDescription(){
ExtraDescr[] extraDescrs=new ExtraDescr[response.description.extra.length];
for (int i=0;i<response.description.extra.length;i++){
extraDescrs[i]=new ExtraDescr();
extraDescrs[i].color=response.description.extra[i].color;
extraDescrs[i].text=response.description.extra[i].text;
if (response.description.extra!=null) {
ExtraDescr[] extraDescrs = new ExtraDescr[response.description.extra.length];
for (int i = 0; i < response.description.extra.length; i++) {
extraDescrs[i] = new ExtraDescr();
extraDescrs[i].color = response.description.extra[i].color;
extraDescrs[i].text = response.description.extra[i].text;
}
return extraDescrs;
}else {
return new ExtraDescr[0];
}
return extraDescrs;
}
@Override
public String getFavicon() {
Expand Down
2 changes: 1 addition & 1 deletion BasicInfoAPI/src/test/conn/MinecraftServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class MinecraftServerTest {
public static void main(String[] args)throws Exception {
MinecraftServer minecraftServer=new MinecraftServer("play.ee-fans.com",25565);
MinecraftServer minecraftServer=new MinecraftServer("cn-cd-dx-1.natfrp.cloud",18904);
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

0 comments on commit 834ccf6

Please sign in to comment.