From 9322c288ac5e39fd49235af49f36d2573ed89a61 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 13 May 2023 16:40:15 -0400 Subject: [PATCH] Upgrade Javalin to 5.5.0 & Fix project warnings --- build.gradle | 10 ++++---- .../emu/grasscutter/command/CommandMap.java | 9 ++++---- .../emu/grasscutter/data/ResourceLoader.java | 23 ++++++++++--------- .../data/excels/monster/MonsterData.java | 11 ++++----- .../grasscutter/database/DatabaseHelper.java | 6 +++-- .../emu/grasscutter/game/avatar/Avatar.java | 18 ++++++++------- .../emu/grasscutter/game/drop/DropInfo.java | 1 + .../game/drop/DropSystemLegacy.java | 1 + .../managers/blossom/BlossomActivity.java | 9 +++++--- .../grasscutter/server/http/HttpServer.java | 16 ++++++++----- .../server/http/handlers/GachaHandler.java | 17 +++++++------- .../send/PacketCodexDataFullNotify.java | 6 ++--- 12 files changed, 71 insertions(+), 56 deletions(-) diff --git a/build.gradle b/build.gradle index 44b63c00b..dc238ea32 100644 --- a/build.gradle +++ b/build.gradle @@ -79,10 +79,10 @@ dependencies { implementation group: 'net.java.dev.jna', name: 'jna', version: '5.10.0' // Java Netty for networking. - implementation group: 'io.netty', name: 'netty-common', version: '4.1.79.Final' - implementation group: 'io.netty', name: 'netty-handler', version: '4.1.79.Final' - implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.79.Final' - implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: '4.1.79.Final' + implementation group: 'io.netty', name: 'netty-common', version: '4.1.86.Final' + implementation group: 'io.netty', name: 'netty-handler', version: '4.1.86.Final' + implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.86.Final' + implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: '4.1.86.Final' // Serialization. implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0' @@ -112,7 +112,7 @@ dependencies { implementation group: 'org.luaj', name: 'luaj-jse', version: '3.0.1' // Java HTTP server library. - implementation group: 'io.javalin', name: 'javalin', version: '4.6.4' + implementation group: 'io.javalin', name: 'javalin', version: '5.5.0' // Google Protocol Buffer definitions. // These are the raw '.proto' files. diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index 0a734cd46..4bdb099eb 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -1,15 +1,16 @@ package emu.grasscutter.command; -import static emu.grasscutter.config.Configuration.SERVER; - import emu.grasscutter.Grasscutter; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.player.Player; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import java.util.*; import org.reflections.Reflections; +import java.util.*; + +import static emu.grasscutter.config.Configuration.SERVER; + @SuppressWarnings({"UnusedReturnValue", "unused"}) public final class CommandMap { private static final int INVALID_UID = Integer.MIN_VALUE; @@ -37,7 +38,7 @@ public final class CommandMap { } catch (NumberFormatException ignored) { var account = DatabaseHelper.getAccountByName(input); if (account == null) return INVALID_UID; - var player = DatabaseHelper.getPlayerByAccount(account); + var player = DatabaseHelper.getPlayerByAccount(account, Player.class); if (player == null) return INVALID_UID; // We will be immediately fetching the player again after this, // but offline vs online Player safety is more important than saving a lookup diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index de5d35ae5..196343ce5 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -1,9 +1,5 @@ package emu.grasscutter.data; -import static emu.grasscutter.utils.FileUtils.getDataPath; -import static emu.grasscutter.utils.FileUtils.getResourcePath; -import static emu.grasscutter.utils.Language.translate; - import com.google.gson.annotations.SerializedName; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.*; @@ -33,6 +29,12 @@ import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArraySet; +import lombok.SneakyThrows; +import lombok.val; +import org.reflections.Reflections; + +import javax.script.Bindings; +import javax.script.CompiledScript; import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.Files; @@ -44,11 +46,10 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.script.Bindings; -import javax.script.CompiledScript; -import lombok.SneakyThrows; -import lombok.val; -import org.reflections.Reflections; + +import static emu.grasscutter.utils.FileUtils.getDataPath; +import static emu.grasscutter.utils.FileUtils.getResourcePath; +import static emu.grasscutter.utils.Language.translate; public final class ResourceLoader { @@ -247,10 +248,10 @@ public final class ResourceLoader { config.points.forEach( (pointId, pointData) -> { val scenePoint = new ScenePointEntry(sceneId, pointData); - scenePoints.add(pointId); + scenePoints.add((int) pointId); pointData.setId(pointId); - GameData.getScenePointIdList().add(pointId); + GameData.getScenePointIdList().add((int) pointId); GameData.getScenePointEntryMap().put((sceneId << 16) + pointId, scenePoint); pointData.updateDailyDungeon(); diff --git a/src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java b/src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java index 0b6739457..f85dbebcc 100644 --- a/src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java +++ b/src/main/java/emu/grasscutter/data/excels/monster/MonsterData.java @@ -9,11 +9,11 @@ import emu.grasscutter.data.common.PropGrowCurve; import emu.grasscutter.data.excels.GadgetData; import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.MonsterType; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; import lombok.Getter; +import java.util.List; +import java.util.Set; + @ResourceType(name = "MonsterExcelConfigData.json", loadPriority = LoadPriority.LOW) @Getter public class MonsterData extends GameResource { @@ -99,10 +99,9 @@ public class MonsterData extends GameResource { if (this.describeData == null) { return; } - for (Entry entry : - GameData.getMonsterSpecialNameDataMap().entrySet()) { + for (var entry : GameData.getMonsterSpecialNameDataMap().int2ObjectEntrySet()) { if (entry.getValue().getSpecialNameLabId() == this.getDescribeData().getSpecialNameLabId()) { - this.specialNameId = entry.getKey(); + this.specialNameId = entry.getIntKey(); break; } } diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index f0cc680e6..ca3d22644 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -1,7 +1,5 @@ package emu.grasscutter.database; -import static com.mongodb.client.model.Filters.eq; - import com.mongodb.client.result.DeleteResult; import dev.morphia.query.FindOptions; import dev.morphia.query.Sort; @@ -22,9 +20,12 @@ import emu.grasscutter.game.mail.Mail; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.GameMainQuest; import emu.grasscutter.game.world.SceneGroupInstance; + import java.util.List; import java.util.stream.Stream; +import static com.mongodb.client.model.Filters.eq; + public final class DatabaseHelper { public static Account createAccount(String username) { return createAccountWithUid(username, 0); @@ -54,6 +55,7 @@ public final class DatabaseHelper { } // Account + @SuppressWarnings("deprecation") Account account = new Account(); account.setUsername(username); account.setId(Integer.toString(DatabaseManager.getNextId(account))); diff --git a/src/main/java/emu/grasscutter/game/avatar/Avatar.java b/src/main/java/emu/grasscutter/game/avatar/Avatar.java index 0b7596565..4b3b3b8b0 100644 --- a/src/main/java/emu/grasscutter/game/avatar/Avatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/Avatar.java @@ -1,15 +1,14 @@ package emu.grasscutter.game.avatar; -import static emu.grasscutter.config.Configuration.GAME_OPTIONS; - import dev.morphia.annotations.*; import emu.grasscutter.GameConstants; import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.OpenConfigEntry; import emu.grasscutter.data.binout.OpenConfigEntry.SkillPointModifier; import emu.grasscutter.data.common.FightPropData; -import emu.grasscutter.data.excels.*; +import emu.grasscutter.data.excels.EquipAffixData; import emu.grasscutter.data.excels.ItemData.WeaponProperty; +import emu.grasscutter.data.excels.ProudSkillData; import emu.grasscutter.data.excels.avatar.AvatarData; import emu.grasscutter.data.excels.avatar.AvatarSkillData; import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; @@ -41,16 +40,19 @@ import emu.grasscutter.net.proto.TrialAvatarInfoOuterClass.TrialAvatarInfo; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.ProtoHelper; import it.unimi.dsi.fastutil.ints.*; -import java.util.*; -import java.util.stream.Stream; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import lombok.val; import org.bson.types.ObjectId; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.*; +import java.util.stream.Stream; + +import static emu.grasscutter.config.Configuration.GAME_OPTIONS; + @Entity(value = "avatars", useDiscriminator = false) public class Avatar { @Transient @Getter private final Int2ObjectMap equips; @@ -316,7 +318,7 @@ public class Avatar { var candSkillDepotId = candSkillDepotIdsList.get(candSkillDepotIndex); // Sanity checks for skill depots - val skillDepot = GameData.getAvatarSkillDepotDataMap().get(candSkillDepotId); + val skillDepot = GameData.getAvatarSkillDepotDataMap().get((int) candSkillDepotId); if (skillDepot == null || skillDepot.getId() == skillDepotId) { return false; } diff --git a/src/main/java/emu/grasscutter/game/drop/DropInfo.java b/src/main/java/emu/grasscutter/game/drop/DropInfo.java index 8ba401eaf..0484d777a 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropInfo.java +++ b/src/main/java/emu/grasscutter/game/drop/DropInfo.java @@ -2,6 +2,7 @@ package emu.grasscutter.game.drop; import java.util.List; +@SuppressWarnings("deprecation") public class DropInfo { private int monsterId; private List dropDataList; diff --git a/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java b/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java index b83bd0f48..2c05e9ef5 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java +++ b/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java @@ -19,6 +19,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.util.List; +@SuppressWarnings("deprecation") public class DropSystemLegacy extends BaseGameSystem { private final Int2ObjectMap> dropData; diff --git a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java index f38e7d222..b6f5a4ca5 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java @@ -107,9 +107,12 @@ public final class BlossomActivity { } generatedCount += willSpawn; for (int i = 0; i < willSpawn; i++) { - var monsterData = GameData.getMonsterDataMap().get(candidateMonsters.poll()); - int level = scene.getEntityLevel(1, worldLevelOverride); - EntityMonster entity = new EntityMonster(scene, monsterData, pos.nearby2d(4f), level); + var entry = candidateMonsters.poll(); + if (entry == null) continue; + + var monsterData = GameData.getMonsterDataMap().get((int) entry); + var level = scene.getEntityLevel(1, worldLevelOverride); + var entity = new EntityMonster(scene, monsterData, pos.nearby2d(4f), level); scene.addEntity(entity); newMonsters.add(entity); } diff --git a/src/main/java/emu/grasscutter/server/http/HttpServer.java b/src/main/java/emu/grasscutter/server/http/HttpServer.java index 010cf198c..23d24b01d 100644 --- a/src/main/java/emu/grasscutter/server/http/HttpServer.java +++ b/src/main/java/emu/grasscutter/server/http/HttpServer.java @@ -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 }); diff --git a/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java index 66300e7b6..482362844 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java @@ -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; + }); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java index 7f74a7839..163932899 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java @@ -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())