-
Notifications
You must be signed in to change notification settings - Fork 1
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
MX233
committed
Oct 7, 2021
1 parent
e1c6d70
commit 92b4be0
Showing
18 changed files
with
484 additions
and
368 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
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
package tax.cute.minecraftinfoapi; | ||
|
||
public class CommonException extends Exception{ | ||
public CommonException(String msg) { | ||
super(msg); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
package tax.cute.minecraftinfoapi; | ||
|
||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import tax.cute.minecraftinfoapi.utils.ApiUrl; | ||
import tax.cute.minecraftinfoapi.utils.Util; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MultiplePlayers { | ||
public Map<String,String> getPlayers(List<String> players) throws IOException,CommonException { | ||
if(players.isEmpty()) | ||
throw new CommonException("Players is empty"); | ||
if(players.size() > 10) | ||
throw new CommonException("Players too big,It cannot be greater than 10"); | ||
JSONArray array = new JSONArray(); | ||
array.addAll(players); | ||
|
||
array = JSONArray.parseArray(Util.sendPost(ApiUrl.PLAYERS,"Content-Type","application/json",array.toJSONString().getBytes())); | ||
|
||
Map<String,String> data = new HashMap<>(); | ||
array.forEach(object -> { | ||
JSONObject jsonObject = (JSONObject)object; | ||
data.put(jsonObject.getString("id"),jsonObject.getString("name")); | ||
}); | ||
|
||
return data; | ||
} | ||
} |
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,61 @@ | ||
package tax.cute.minecraftinfoapi; | ||
|
||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import tax.cute.minecraftinfoapi.utils.ApiUrl; | ||
import tax.cute.minecraftinfoapi.utils.Http; | ||
import tax.cute.minecraftinfoapi.utils.Util; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class NameHistory { | ||
private final List<NameHistoryData> nameHistoryData; | ||
private final String uuid; | ||
|
||
public NameHistory( | ||
List<NameHistoryData> nameHistoryData, | ||
String uuid | ||
) { | ||
this.nameHistoryData = nameHistoryData; | ||
this.uuid = uuid; | ||
} | ||
|
||
public static NameHistory getNameHistory(String uuid) throws IOException,CommonException { | ||
if (uuid == null || uuid.isEmpty() || !Util.isUuid(uuid)) | ||
throw new CommonException("Input error"); | ||
Http http = Http.getHttp(ApiUrl.NAME_HISTORY | ||
.replace("%uuid", uuid) | ||
); | ||
if (http.getCode() != HttpURLConnection.HTTP_OK) | ||
throw new CommonException("no this player"); | ||
|
||
List<NameHistoryData> nameHistoryData = new ArrayList<>(); | ||
|
||
JSONArray array = JSONArray.parseArray(http.getTextString()); | ||
array.forEach(object -> { | ||
JSONObject json = (JSONObject) object; | ||
nameHistoryData.add(new NameHistoryData(json.getString("name"), Util.notNullLong(json.getLong("changedToAt")))); | ||
}); | ||
|
||
return new NameHistory(nameHistoryData,uuid); | ||
} | ||
|
||
public List<NameHistoryData> getNameHistoryData() { | ||
return nameHistoryData; | ||
} | ||
|
||
public String getInitName() { | ||
return nameHistoryData.get(0).getName(); | ||
} | ||
|
||
public String getCurrentName() { | ||
return nameHistoryData.get(nameHistoryData.size() - 1).getName(); | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
} |
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 tax.cute.minecraftinfoapi; | ||
|
||
public class NameHistoryData { | ||
private final String name; | ||
private final long changedToAt; | ||
|
||
public NameHistoryData( | ||
String name, | ||
long changedToAt | ||
) { | ||
this.name = name; | ||
this.changedToAt = changedToAt; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public long getChangedToAt() { | ||
return changedToAt; | ||
} | ||
} |
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,40 @@ | ||
package tax.cute.minecraftinfoapi; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import tax.cute.minecraftinfoapi.utils.*; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
|
||
public class Player { | ||
private final String name; | ||
private final String uuid; | ||
|
||
public Player( | ||
String name, | ||
String uuid | ||
) { | ||
this.name = name; | ||
this.uuid = uuid; | ||
} | ||
|
||
public static Player getPlayer(String name) throws IOException,CommonException { | ||
if (name == null || name.isEmpty() || !Util.isLegalUsername(name))throw new CommonException("Illegal username"); | ||
Http http = Http.getHttp(ApiUrl.PLAYER | ||
.replace("%name",name) | ||
); | ||
|
||
if (http.getCode() != HttpURLConnection.HTTP_OK)throw new CommonException("No this player"); | ||
|
||
JSONObject json = JSONObject.parseObject(http.getTextString()); | ||
return new Player(json.getString("name"),json.getString("id")); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
} |
Oops, something went wrong.