forked from MinecraftUtilities/Backend
initial commit
This commit is contained in:
commit
f68d941dc8
143
.gitignore
vendored
Normal file
143
.gitignore
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store### Intellij template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Java template
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
### Minecraft Helper ###
|
||||
application.yml
|
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="azul-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
67
pom.xml
Normal file
67
pom.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>cc.fascinated</groupId>
|
||||
<artifactId>Minecraft-Helper</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.32</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.20.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.20.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.jodah</groupId>
|
||||
<artifactId>expiringmap</artifactId>
|
||||
<version>0.5.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
35
src/main/java/cc/fascinated/Main.java
Normal file
35
src/main/java/cc/fascinated/Main.java
Normal file
@ -0,0 +1,35 @@
|
||||
package cc.fascinated;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Objects;
|
||||
|
||||
@SpringBootApplication @Log4j2
|
||||
public class Main {
|
||||
|
||||
@Getter
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
File config = new File("application.yml");
|
||||
if (!config.exists()) { // Saving the default config if it doesn't exist locally
|
||||
Files.copy(Objects.requireNonNull(Main.class.getResourceAsStream("/application.yml")), config.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
log.info("Saved the default configuration to '{}', please re-launch the application", // Log the default config being saved
|
||||
config.getAbsolutePath()
|
||||
);
|
||||
return;
|
||||
}
|
||||
log.info("Found configuration at '{}'", config.getAbsolutePath()); // Log the found config
|
||||
|
||||
SpringApplication.run(Main.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cc.fascinated.api.controller;
|
||||
|
||||
import cc.fascinated.player.PlayerManagerService;
|
||||
import cc.fascinated.player.impl.Player;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public class PlayerController {
|
||||
|
||||
private final PlayerManagerService playerManagerService;
|
||||
|
||||
@Autowired
|
||||
public PlayerController(PlayerManagerService playerManagerService) {
|
||||
this.playerManagerService = playerManagerService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}") @ResponseBody
|
||||
public ResponseEntity<Player> getPlayer(@PathVariable String id) {
|
||||
Player player = playerManagerService.getPlayer(id);
|
||||
if (player == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.ok(player);
|
||||
}
|
||||
}
|
59
src/main/java/cc/fascinated/mojang/MojangAPIService.java
Normal file
59
src/main/java/cc/fascinated/mojang/MojangAPIService.java
Normal file
@ -0,0 +1,59 @@
|
||||
package cc.fascinated.mojang;
|
||||
|
||||
import cc.fascinated.Main;
|
||||
import cc.fascinated.mojang.types.MojangApiProfile;
|
||||
import cc.fascinated.mojang.types.MojangSessionServerProfile;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
@Service
|
||||
public class MojangAPIService {
|
||||
|
||||
private static final HttpClient CLIENT = HttpClient.newHttpClient();
|
||||
|
||||
@Value("${mojang.session-server}")
|
||||
private String mojangSessionServerUrl;
|
||||
|
||||
@Value("${mojang.api}")
|
||||
private String mojangApiUrl;
|
||||
|
||||
/**
|
||||
* Gets the Session Server profile of the player with the given UUID.
|
||||
*
|
||||
* @param id the uuid or name of the player
|
||||
* @return the profile
|
||||
*/
|
||||
@SneakyThrows
|
||||
public MojangSessionServerProfile getSessionServerProfile(String id) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(new URI(mojangSessionServerUrl + "/session/minecraft/profile/" + id))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return Main.getGSON().fromJson(response.body(), MojangSessionServerProfile.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Mojang API profile of the player with the given UUID.
|
||||
*
|
||||
* @param id the name of the player
|
||||
* @return the profile
|
||||
*/
|
||||
@SneakyThrows
|
||||
public MojangApiProfile getApiProfile(String id) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(new URI(mojangApiUrl + "/users/profiles/minecraft/" + id))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return Main.getGSON().fromJson(response.body(), MojangApiProfile.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cc.fascinated.mojang.types;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class MojangApiProfile {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public MojangApiProfile() {}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package cc.fascinated.mojang.types;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter @ToString
|
||||
public class MojangSessionServerProfile {
|
||||
|
||||
/**
|
||||
* The UUID of the player.
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* The name of the player.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* The properties for the player.
|
||||
*/
|
||||
private final List<MojangSessionServerProfileProperties> properties = new ArrayList<>();
|
||||
|
||||
public MojangSessionServerProfile() {}
|
||||
|
||||
/**
|
||||
* Get the texture property for the player.
|
||||
*
|
||||
* @return the texture property
|
||||
*/
|
||||
public MojangSessionServerProfileProperties getTextureProperty() {
|
||||
for (MojangSessionServerProfileProperties property : properties) {
|
||||
if (property.getName().equals("textures")) {
|
||||
return property;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cc.fascinated.mojang.types;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter @ToString
|
||||
public class MojangSessionServerProfileProperties {
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public MojangSessionServerProfileProperties() {}
|
||||
}
|
72
src/main/java/cc/fascinated/player/PlayerManagerService.java
Normal file
72
src/main/java/cc/fascinated/player/PlayerManagerService.java
Normal file
@ -0,0 +1,72 @@
|
||||
package cc.fascinated.player;
|
||||
|
||||
import cc.fascinated.mojang.MojangAPIService;
|
||||
import cc.fascinated.mojang.types.MojangApiProfile;
|
||||
import cc.fascinated.mojang.types.MojangSessionServerProfile;
|
||||
import cc.fascinated.player.impl.Player;
|
||||
import cc.fascinated.util.UUIDUtils;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class PlayerManagerService {
|
||||
|
||||
/**
|
||||
* The cache of players.
|
||||
*/
|
||||
private final Map<UUID, Player> players = ExpiringMap.builder()
|
||||
.expiration(1, TimeUnit.HOURS)
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* The cache of player names to UUIDs.
|
||||
*/
|
||||
private final Map<String, UUID> playerNameToUUIDCache = ExpiringMap.builder()
|
||||
.expiration(1, TimeUnit.DAYS)
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.build();
|
||||
|
||||
private final MojangAPIService mojangAPIService;
|
||||
|
||||
public PlayerManagerService(MojangAPIService mojangAPIService) {
|
||||
this.mojangAPIService = mojangAPIService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player by their UUID.
|
||||
*
|
||||
* @param id the uuid or name of the player
|
||||
* @return the player or null if the player does not exist
|
||||
*/
|
||||
public Player getPlayer(String id) {
|
||||
UUID uuid;
|
||||
if (id.length() == 32 || id.length() == 36) {
|
||||
uuid = UUID.fromString(id.length() == 32 ? UUIDUtils.addUUIDDashes(id) : id);
|
||||
} else {
|
||||
uuid = playerNameToUUIDCache.get(id.toUpperCase());
|
||||
}
|
||||
|
||||
if (players.containsKey(uuid)) {
|
||||
return players.get(uuid);
|
||||
}
|
||||
|
||||
MojangSessionServerProfile profile = uuid == null ? null : mojangAPIService.getSessionServerProfile(uuid.toString());
|
||||
if (profile == null) {
|
||||
MojangApiProfile apiProfile = mojangAPIService.getApiProfile(id);
|
||||
if (apiProfile == null) {
|
||||
return null;
|
||||
}
|
||||
profile = mojangAPIService.getSessionServerProfile(apiProfile.getId().length() == 32 ? UUIDUtils.addUUIDDashes(apiProfile.getId()) : apiProfile.getId());
|
||||
}
|
||||
Player player = new Player(profile);
|
||||
players.put(player.getUuid(), player);
|
||||
playerNameToUUIDCache.put(player.getName().toUpperCase(), player.getUuid());
|
||||
return player;
|
||||
}
|
||||
}
|
57
src/main/java/cc/fascinated/player/impl/Player.java
Normal file
57
src/main/java/cc/fascinated/player/impl/Player.java
Normal file
@ -0,0 +1,57 @@
|
||||
package cc.fascinated.player.impl;
|
||||
|
||||
import cc.fascinated.Main;
|
||||
import cc.fascinated.mojang.types.MojangSessionServerProfile;
|
||||
import cc.fascinated.mojang.types.MojangSessionServerProfileProperties;
|
||||
import cc.fascinated.util.UUIDUtils;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class Player {
|
||||
|
||||
/**
|
||||
* The UUID of the player
|
||||
*/
|
||||
private final UUID uuid;
|
||||
|
||||
/**
|
||||
* The name of the player
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The skin of the player
|
||||
* <p>
|
||||
* This will be null if the player does not have a skin.
|
||||
* </p>
|
||||
*/
|
||||
private Skin skin;
|
||||
|
||||
public Player(MojangSessionServerProfile profile) {
|
||||
this.uuid = UUID.fromString(UUIDUtils.addUUIDDashes(profile.getId()));
|
||||
this.name = profile.getName();
|
||||
|
||||
MojangSessionServerProfileProperties textureProperty = profile.getTextureProperty();
|
||||
if (textureProperty == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decode the texture property
|
||||
String decoded = new String(java.util.Base64.getDecoder().decode(textureProperty.getValue()));
|
||||
|
||||
// Parse the decoded JSON
|
||||
JsonObject json = Main.getGSON().fromJson(decoded, JsonObject.class);
|
||||
JsonObject textures = json.getAsJsonObject("textures");
|
||||
JsonObject skin = textures.getAsJsonObject("SKIN");
|
||||
JsonObject metadata = skin.get("metadata").getAsJsonObject();
|
||||
|
||||
String url = skin.get("url").getAsString();
|
||||
SkinType model = SkinType.fromString(metadata.get("model").getAsString());
|
||||
|
||||
this.skin = new Skin(url, model);
|
||||
}
|
||||
|
||||
}
|
18
src/main/java/cc/fascinated/player/impl/Skin.java
Normal file
18
src/main/java/cc/fascinated/player/impl/Skin.java
Normal file
@ -0,0 +1,18 @@
|
||||
package cc.fascinated.player.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter @AllArgsConstructor
|
||||
public class Skin {
|
||||
|
||||
/**
|
||||
* The URL of the skin
|
||||
*/
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* The model of the skin
|
||||
*/
|
||||
private final SkinType model;
|
||||
}
|
22
src/main/java/cc/fascinated/player/impl/SkinType.java
Normal file
22
src/main/java/cc/fascinated/player/impl/SkinType.java
Normal file
@ -0,0 +1,22 @@
|
||||
package cc.fascinated.player.impl;
|
||||
|
||||
public enum SkinType {
|
||||
|
||||
DEFAULT,
|
||||
SLIM;
|
||||
|
||||
/**
|
||||
* Get the skin type from a string
|
||||
*
|
||||
* @param string the string
|
||||
* @return the skin type
|
||||
*/
|
||||
public static SkinType fromString(String string) {
|
||||
for (SkinType type : values()) {
|
||||
if (type.name().equalsIgnoreCase(string)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
19
src/main/java/cc/fascinated/util/UUIDUtils.java
Normal file
19
src/main/java/cc/fascinated/util/UUIDUtils.java
Normal file
@ -0,0 +1,19 @@
|
||||
package cc.fascinated.util;
|
||||
|
||||
public class UUIDUtils {
|
||||
|
||||
/**
|
||||
* Add dashes to a UUID.
|
||||
*
|
||||
* @param idNoDashes the UUID without dashes
|
||||
* @return the UUID with dashes
|
||||
*/
|
||||
public static String addUUIDDashes(String idNoDashes) {
|
||||
StringBuilder idBuff = new StringBuilder(idNoDashes);
|
||||
idBuff.insert(20, '-');
|
||||
idBuff.insert(16, '-');
|
||||
idBuff.insert(12, '-');
|
||||
idBuff.insert(8, '-');
|
||||
return idBuff.toString();
|
||||
}
|
||||
}
|
7
src/main/resources/application.yml
Normal file
7
src/main/resources/application.yml
Normal file
@ -0,0 +1,7 @@
|
||||
server:
|
||||
address: 0.0.0.0
|
||||
port: 7500
|
||||
|
||||
mojang:
|
||||
session-server: https://sessionserver.mojang.com
|
||||
api: https://api.mojang.com
|
Loading…
x
Reference in New Issue
Block a user