-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
core/src/main/java/net/smyler/terramap/http/UserAgent.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,48 @@ | ||
package net.smyler.terramap.http; | ||
|
||
import net.smyler.smylib.SmyLib; | ||
import net.smyler.smylib.game.GameClient; | ||
import net.smyler.terramap.Terramap; | ||
|
||
import static java.lang.System.getProperty; | ||
|
||
public final class UserAgent { | ||
|
||
public static String buildUserAgent(GameClient client, Terramap terramap) { | ||
StringBuilder userAgent = new StringBuilder(); | ||
terramap.version(); | ||
SmyLib.getGameClient().modLoader(); | ||
|
||
userAgent.append(modString(terramap)).append(" "); | ||
|
||
userAgent.append(loaderString(client)).append(" "); | ||
userAgent.append(mcString(client)).append(" "); | ||
|
||
return userAgent.toString(); | ||
} | ||
|
||
private static String osString() { | ||
return getProperty("os.name", "unknown"); | ||
} | ||
|
||
private static String javaString() { | ||
String version = getProperty("java.version"); | ||
return "Java" + (version != null ? "/" + version : ""); | ||
} | ||
|
||
private static String mcString(GameClient client) { | ||
return "Minecraft/" + client.gameVersion(); | ||
} | ||
|
||
private static String loaderString(GameClient client) { | ||
return client.modLoader(); | ||
} | ||
|
||
private static String modString(Terramap terramap) { | ||
return String.format("Terramap/%s (%s; %s; +https://github.com/SmylerMC/terramap)", | ||
terramap.version(), | ||
osString(), | ||
javaString() | ||
); | ||
} | ||
} |
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