This commit is contained in:
23
src/main/java/cc.fascinated/controller/HomeController.java
Normal file
23
src/main/java/cc.fascinated/controller/HomeController.java
Normal file
@ -0,0 +1,23 @@
|
||||
package cc.fascinated.controller;
|
||||
|
||||
import cc.fascinated.config.Config;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/")
|
||||
public class HomeController {
|
||||
|
||||
/**
|
||||
* The example UUID.
|
||||
*/
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";
|
||||
|
||||
@RequestMapping(value = "/")
|
||||
public String home(Model model) {
|
||||
model.addAttribute("player_example_url", Config.INSTANCE.getWebPublicUrl() + "/player/" + exampleUuid);
|
||||
return "index";
|
||||
}
|
||||
}
|
48
src/main/java/cc.fascinated/controller/PlayerController.java
Normal file
48
src/main/java/cc.fascinated/controller/PlayerController.java
Normal file
@ -0,0 +1,48 @@
|
||||
package cc.fascinated.controller;
|
||||
|
||||
import cc.fascinated.common.PlayerUtils;
|
||||
import cc.fascinated.model.player.Player;
|
||||
import cc.fascinated.model.player.Skin;
|
||||
import cc.fascinated.service.PlayerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/player/")
|
||||
public class PlayerController {
|
||||
|
||||
private final CacheControl cacheControl = CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic();
|
||||
private final PlayerService playerManagerService;
|
||||
|
||||
@Autowired
|
||||
public PlayerController(PlayerService playerManagerService) {
|
||||
this.playerManagerService = playerManagerService;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<?> getPlayer(@PathVariable String id) {
|
||||
return ResponseEntity.ok()
|
||||
.cacheControl(cacheControl)
|
||||
.body(playerManagerService.getPlayer(id));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{part}/{id}")
|
||||
public ResponseEntity<?> getPlayerHead(@PathVariable String part,
|
||||
@PathVariable String id,
|
||||
@RequestParam(required = false, defaultValue = "256") int size) {
|
||||
Player player = playerManagerService.getPlayer(id);
|
||||
Skin.Parts skinPart = Skin.Parts.fromName(part);
|
||||
|
||||
// Return the part image
|
||||
return ResponseEntity.ok()
|
||||
.cacheControl(cacheControl)
|
||||
.contentType(MediaType.IMAGE_PNG)
|
||||
.body(PlayerUtils.getSkinPartBytes(player.getSkin(), skinPart, size));
|
||||
}
|
||||
}
|
32
src/main/java/cc.fascinated/controller/ServerController.java
Normal file
32
src/main/java/cc.fascinated/controller/ServerController.java
Normal file
@ -0,0 +1,32 @@
|
||||
package cc.fascinated.controller;
|
||||
|
||||
import cc.fascinated.model.cache.CachedMinecraftServer;
|
||||
import cc.fascinated.model.server.MinecraftServer;
|
||||
import cc.fascinated.service.ServerService;
|
||||
import cc.fascinated.service.pinger.impl.JavaMinecraftServerPinger;
|
||||
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 = "/server/")
|
||||
public class ServerController {
|
||||
|
||||
@Autowired
|
||||
private ServerService serverService;
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/{platform}/{hostnameAndPort}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public CachedMinecraftServer getServer(@PathVariable String platform, @PathVariable String hostnameAndPort) {
|
||||
String[] split = hostnameAndPort.split(":");
|
||||
String hostname = split[0];
|
||||
int port = 25565;
|
||||
if (split.length == 2) {
|
||||
try {
|
||||
port = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
return serverService.getServer(platform, hostname, port);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user