generated from TobiasDeBruijn/BaseBukkitPlugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Switched from Apache's HTTP client to my own HttpLib - Switched from org.json to Google's gson - Added LOG4J for JDA's Logging needs - Switched to reflection for applying the skin, this means we're less version dependant (It works until Mojang changes its code) - Added several Util functions - Added a Triple, this is sortof to emulate Rust's Result - Renamed and moved some things around to comform to Google's naming standards and to make the codebase more organized
- Loading branch information
Tobias de Bruijn
committed
Mar 18, 2021
1 parent
0cda9f6
commit 024c94a
Showing
25 changed files
with
383 additions
and
420 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
.../java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
.../java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r2.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
.../java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r3.java
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
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
67 changes: 67 additions & 0 deletions
67
src/main/java/nl/thedutchmc/SkinFixer/apis/MineskinApi.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,67 @@ | ||
package nl.thedutchmc.SkinFixer.apis; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import nl.thedutchmc.SkinFixer.SkinFixer; | ||
import nl.thedutchmc.SkinFixer.gson.GetSkinResponse; | ||
import nl.thedutchmc.SkinFixer.util.Triple; | ||
import nl.thedutchmc.SkinFixer.util.Utils; | ||
import nl.thedutchmc.httplib.Http; | ||
import nl.thedutchmc.httplib.Http.RequestMethod; | ||
import nl.thedutchmc.httplib.Http.ResponseObject; | ||
|
||
|
||
public class MineskinApi { | ||
|
||
public Triple<Boolean, GetSkinResponse, String> getSkin(String skinUrl, boolean slim) { | ||
HashMap<String, String> urlParameters = new HashMap<>(); | ||
urlParameters.put("User-Agent", "SkinFixer"); | ||
urlParameters.put("url", skinUrl); | ||
|
||
if(slim) { | ||
urlParameters.put("model", "slim"); | ||
} | ||
|
||
ResponseObject apiResponse; | ||
try { | ||
apiResponse = new Http().makeRequest(RequestMethod.POST, "https://api.mineskin.org/generate/url", urlParameters, null, null, null); | ||
} catch(IOException e) { | ||
SkinFixer.logWarn("An IOException occured while fetching a skin."); | ||
//TODO logDebug | ||
|
||
return new Triple<Boolean, GetSkinResponse, String>(false, null, Utils.getStackTrace(e)); | ||
} | ||
|
||
if(apiResponse.getResponseCode() != 200) { | ||
SkinFixer.logWarn("The MineSkin API returned an unexpected result: " + apiResponse.getConnectionMessage()); | ||
return new Triple<Boolean, GetSkinResponse, String>(false, null, apiResponse.getConnectionMessage()); | ||
} | ||
|
||
final Gson gson = new Gson(); | ||
return new Triple<Boolean, GetSkinResponse, String>(true, gson.fromJson(apiResponse.getMessage(), GetSkinResponse.class), null); | ||
} | ||
|
||
public Triple<Boolean, GetSkinResponse, String> getSkinOfPremiumPlayer(String uuid) { | ||
|
||
ResponseObject apiResponse; | ||
try { | ||
apiResponse = new Http().makeRequest(RequestMethod.GET, "https://api.mineskin.org/generate/user/" + uuid, null, null, null, null); | ||
} catch(IOException e) { | ||
SkinFixer.logWarn("An IOException occured while fetching a skin."); | ||
//TODO logDebug | ||
|
||
return new Triple<Boolean, GetSkinResponse, String>(false, null, Utils.getStackTrace(e)); | ||
} | ||
|
||
if(apiResponse.getResponseCode() != 200) { | ||
SkinFixer.logWarn("The MineSkin API returned an unexpected result: " + apiResponse.getConnectionMessage()); | ||
return new Triple<Boolean, GetSkinResponse, String>(false, null, apiResponse.getConnectionMessage()); | ||
} | ||
|
||
final Gson gson = new Gson(); | ||
return new Triple<Boolean, GetSkinResponse, String>(true, gson.fromJson(apiResponse.getMessage(), GetSkinResponse.class), null); | ||
} | ||
} |
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,46 @@ | ||
package nl.thedutchmc.SkinFixer.apis; | ||
|
||
import java.io.IOException; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import nl.thedutchmc.SkinFixer.SkinFixer; | ||
import nl.thedutchmc.SkinFixer.gson.MojangAuthResponse; | ||
import nl.thedutchmc.SkinFixer.util.Triple; | ||
import nl.thedutchmc.SkinFixer.util.Utils; | ||
import nl.thedutchmc.httplib.Http; | ||
import nl.thedutchmc.httplib.Http.MediaFormat; | ||
import nl.thedutchmc.httplib.Http.RequestMethod; | ||
import nl.thedutchmc.httplib.Http.ResponseObject; | ||
|
||
public class MojangApi { | ||
|
||
public Triple<Boolean, MojangAuthResponse, String> getUuidFromMojang(String playername) { | ||
String requestBody = "[\"" + playername + "\"]"; | ||
|
||
ResponseObject apiResponse; | ||
try { | ||
apiResponse = new Http().makeRequest(RequestMethod.POST, "https://api.mojang.com/profiles/minecraft", null, MediaFormat.JSON, requestBody, null); | ||
} catch(IOException e) { | ||
SkinFixer.logWarn("An IOException occured while fetching a UUID from Mojang."); | ||
//TODO logDebug | ||
|
||
return new Triple<Boolean, MojangAuthResponse, String>(false, null, Utils.getStackTrace(e)); | ||
} | ||
|
||
if(apiResponse.getResponseCode() != 200) { | ||
SkinFixer.logWarn("The Mojang API returned an unexpected result: " + apiResponse.getConnectionMessage()); | ||
return new Triple<Boolean, MojangAuthResponse, String>(false, null, apiResponse.getConnectionMessage()); | ||
} | ||
|
||
|
||
final Gson gson = new Gson(); | ||
MojangAuthResponse[] authResponse = gson.fromJson(apiResponse.getMessage(), MojangAuthResponse[].class); | ||
|
||
if(authResponse.length == 0) { | ||
return new Triple<Boolean, MojangAuthResponse, String>(true, null, null); | ||
} | ||
|
||
return new Triple<Boolean, MojangAuthResponse, String>(true, authResponse[0], null); | ||
} | ||
} |
Oops, something went wrong.