mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-21 11:24:47 +01:00
Upgrade Javalin to 5.5.0 & Fix project warnings
This commit is contained in:
@@ -11,6 +11,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.*;
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
@@ -28,22 +29,25 @@ public final class HttpServer {
|
||||
public HttpServer() {
|
||||
this.javalin = Javalin.create(config -> {
|
||||
// Set the Javalin HTTP server.
|
||||
config.server(HttpServer::createServer);
|
||||
config.jetty.server(HttpServer::createServer);
|
||||
|
||||
// Configure encryption/HTTPS/SSL.
|
||||
config.enforceSsl = HTTP_ENCRYPTION.useEncryption;
|
||||
if (HTTP_ENCRYPTION.useEncryption)
|
||||
config.plugins.enableSslRedirects();
|
||||
|
||||
// Configure HTTP policies.
|
||||
if (HTTP_POLICIES.cors.enabled) {
|
||||
var allowedOrigins = HTTP_POLICIES.cors.allowedOrigins;
|
||||
if (allowedOrigins.length > 0)
|
||||
config.enableCorsForOrigin(allowedOrigins);
|
||||
else config.enableCorsForAllOrigins();
|
||||
config.plugins.enableCors(cors -> cors.add(corsConfig -> {
|
||||
if (allowedOrigins.length > 0)
|
||||
corsConfig.allowHost(Arrays.toString(allowedOrigins));
|
||||
else corsConfig.anyHost();
|
||||
}));
|
||||
}
|
||||
|
||||
// Configure debug logging.
|
||||
if (DISPATCH_INFO.logRequests == ServerDebugMode.ALL)
|
||||
config.enableDevLogging();
|
||||
config.plugins.enableDevLogging();
|
||||
|
||||
// Static files should be added like this https://javalin.io/documentation#static-files
|
||||
});
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package emu.grasscutter.server.http.handlers;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.Account;
|
||||
@@ -15,6 +13,8 @@ import io.javalin.Javalin;
|
||||
import io.javalin.http.ContentType;
|
||||
import io.javalin.http.Context;
|
||||
import io.javalin.http.staticfiles.Location;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -22,7 +22,8 @@ import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
/** Handles all gacha-related HTTP requests. */
|
||||
public final class GachaHandler implements Router {
|
||||
@@ -144,10 +145,10 @@ public final class GachaHandler implements Router {
|
||||
javalin.get("/gacha", GachaHandler::gachaRecords);
|
||||
javalin.get("/gacha/details", GachaHandler::gachaDetails);
|
||||
|
||||
javalin._conf.addSinglePageRoot(
|
||||
"/gacha/mappings",
|
||||
gachaMappingsPath.toString(),
|
||||
Location.EXTERNAL); // TODO: This ***must*** be changed to take the Path not a String. This
|
||||
// might involve upgrading Javalin.
|
||||
javalin.cfg.staticFiles.add(cfg -> {
|
||||
cfg.hostedPath = gachaMappingsPath.toString();
|
||||
cfg.directory = "/gacha/mappings";
|
||||
cfg.location = Location.EXTERNAL;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PacketCodexDataFullNotify extends BasePacket {
|
||||
.getUnlockedWeapon()
|
||||
.forEach(
|
||||
weapon -> {
|
||||
var codexWeapon = GameData.getCodexWeaponDataIdMap().get(weapon);
|
||||
var codexWeapon = GameData.getCodexWeaponDataIdMap().get((int) weapon);
|
||||
if (codexWeapon != null) {
|
||||
weaponTypeData
|
||||
.addCodexIdList(codexWeapon.getId())
|
||||
@@ -69,7 +69,7 @@ public class PacketCodexDataFullNotify extends BasePacket {
|
||||
.getUnlockedAnimal()
|
||||
.forEach(
|
||||
(animal, amount) -> {
|
||||
var codexAnimal = GameData.getCodexAnimalDataMap().get(animal);
|
||||
var codexAnimal = GameData.getCodexAnimalDataMap().get((int) animal);
|
||||
if (codexAnimal != null) {
|
||||
animalTypeData
|
||||
.addCodexIdList(codexAnimal.getId())
|
||||
@@ -82,7 +82,7 @@ public class PacketCodexDataFullNotify extends BasePacket {
|
||||
.getUnlockedMaterial()
|
||||
.forEach(
|
||||
material -> {
|
||||
var codexMaterial = GameData.getCodexMaterialDataIdMap().get(material);
|
||||
var codexMaterial = GameData.getCodexMaterialDataIdMap().get((int) material);
|
||||
if (codexMaterial != null) {
|
||||
materialTypeData
|
||||
.addCodexIdList(codexMaterial.getId())
|
||||
|
||||
Reference in New Issue
Block a user