-
-
Notifications
You must be signed in to change notification settings - Fork 31
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 #259 from Sylfare/fix/build
fix: Make GitHub Actions working again
- Loading branch information
Showing
11 changed files
with
177 additions
and
22 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 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
30 changes: 30 additions & 0 deletions
30
vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/IOUtil.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,30 @@ | ||
package org.oddlama.vane.proxycore.util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public class IOUtil { | ||
private static String read_all(Reader rd) throws IOException { | ||
final var sb = new StringBuilder(); | ||
int cp; | ||
while ((cp = rd.read()) != -1) { | ||
sb.append((char) cp); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
public static JSONObject read_json_from_url(String url) throws IOException, JSONException, URISyntaxException { | ||
try (final var rd = new BufferedReader( | ||
new InputStreamReader(new URI(url).toURL().openStream(), StandardCharsets.UTF_8))) { | ||
return new JSONObject(read_all(rd)); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Resolve.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,37 @@ | ||
package org.oddlama.vane.proxycore.util; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.UUID; | ||
|
||
import org.json.JSONException; | ||
|
||
public class Resolve { | ||
public static class Skin { | ||
|
||
public String texture; | ||
public String signature; | ||
} | ||
|
||
public static Skin resolve_skin(UUID id) throws IOException, JSONException, URISyntaxException { | ||
final var url = "https://sessionserver.mojang.com/session/minecraft/profile/" + id + "?unsigned=false"; | ||
|
||
final var json = IOUtil.read_json_from_url(url); | ||
final var skin = new Skin(); | ||
final var obj = json.getJSONArray("properties").getJSONObject(0); | ||
skin.texture = obj.getString("value"); | ||
skin.signature = obj.getString("signature"); | ||
return skin; | ||
} | ||
|
||
public static UUID resolve_uuid(String name) throws IOException, JSONException, URISyntaxException { | ||
final var url = "https://api.mojang.com/users/profiles/minecraft/" + name; | ||
|
||
final var json = IOUtil.read_json_from_url(url); | ||
final var id_str = json.getString("id"); | ||
final var uuid_str = id_str.replaceFirst( | ||
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", | ||
"$1-$2-$3-$4-$5"); | ||
return UUID.fromString(uuid_str); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/TimeUtil.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 org.oddlama.vane.proxycore.util; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TimeUtil { | ||
private static Map<Character, Long> time_multiplier; | ||
|
||
static { | ||
Map<Character, Long> mult = new HashMap<>(); | ||
mult.put('s', 1000L); // seconds | ||
mult.put('m', 60000L); // minutes | ||
mult.put('h', 3600000L); // hours | ||
mult.put('d', 86400000L); // days | ||
mult.put('w', 604800000L); // weeks | ||
mult.put('y', 31536000000L); // years | ||
time_multiplier = mult; | ||
} | ||
|
||
public static long parse_time(String input) throws NumberFormatException { | ||
long ret = 0; | ||
|
||
for (String time : input.split("(?<=[^0-9])(?=[0-9])")) { | ||
String content[] = time.split("(?=[^0-9])"); | ||
|
||
if (content.length != 2) { | ||
throw new NumberFormatException("missing multiplier"); | ||
} | ||
|
||
Long mult = time_multiplier.get(content[1].replace("and", "").replaceAll("[,+\\.\\s]+", "").charAt(0)); | ||
if (mult == null) { | ||
throw new NumberFormatException("\"" + content[1] + "\" is not a valid multiplier"); | ||
} | ||
|
||
ret += Long.parseLong(content[0]) * mult; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
public static String format_time(long millis) { | ||
String ret = ""; | ||
|
||
long days = millis / 86400000L; | ||
long hours = (millis / 3600000L) % 24; | ||
long minutes = (millis / 60000L) % 60; | ||
long seconds = (millis / 1000L) % 60; | ||
|
||
if (days > 0) { | ||
ret += days + "d"; | ||
} | ||
|
||
if (hours > 0) { | ||
ret += hours + "h"; | ||
} | ||
|
||
if (minutes > 0) { | ||
ret += minutes + "m"; | ||
} | ||
|
||
if (seconds > 0 || ret.length() == 0) { | ||
ret += seconds + "s"; | ||
} | ||
|
||
return ret; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Version.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,7 @@ | ||
package org.oddlama.vane.proxycore.util; | ||
|
||
public final class Version { | ||
|
||
public static final String VERSION = "$VERSION"; | ||
|
||
} |
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