-
-
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.
Merge pull request #33 from udu3324/master
update
- Loading branch information
Showing
16 changed files
with
360 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# These are supported funding model platforms | ||
|
||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: udu3324 | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry | ||
polar: # Replace with a single Polar username | ||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
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
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
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 com.udu3324.poinpow.api; | ||
|
||
import com.udu3324.poinpow.Poinpow; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Minecraft { | ||
public static Map<String, String> uuidOfPlayers = new HashMap<>(); | ||
|
||
//this gets a player's uuid from their ign | ||
public static String getUUID(String ign) { | ||
try { | ||
//check if player's uuid has already been cached | ||
if (uuidOfPlayers.containsKey(ign)) { | ||
//Poinpow.log.info("ign {} cached with uuid {}", uuid, playerRank.get(ign)); | ||
return uuidOfPlayers.get(ign); | ||
} | ||
|
||
URL apiURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + ign); | ||
HttpURLConnection connection = (HttpURLConnection) apiURL.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
|
||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { | ||
Poinpow.log.error("Player ({}) not found! ({})", ign, connection.getResponseCode()); | ||
return null; | ||
} | ||
|
||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
String inputLine; | ||
StringBuilder response = new StringBuilder(); | ||
while ((inputLine = in.readLine()) != null) { | ||
response.append(inputLine); | ||
} | ||
|
||
String json = response.toString().replaceAll(" ", ""); | ||
|
||
connection.disconnect(); | ||
|
||
//parse uuid | ||
int start = json.indexOf("id\":\"") + 5; | ||
int end = json.indexOf("\",\"", start); | ||
|
||
json = json.substring(start, end); | ||
|
||
uuidOfPlayers.put(ign, json); | ||
|
||
return json; | ||
} catch (Exception e) { | ||
Poinpow.log.error("Response to minecraft api was unsuccessful. Player ign: {} - {}", ign, e); | ||
return null; | ||
} | ||
} | ||
|
||
public static String insertUUIDDashes(String uuid) { | ||
StringBuilder sb = new StringBuilder(uuid); | ||
sb.insert(8, "-"); | ||
sb.insert(13, "-"); | ||
sb.insert(18, "-"); | ||
sb.insert(23, "-"); | ||
return sb.toString(); | ||
} | ||
} |
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
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
Oops, something went wrong.