diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000000..3e4a382ed45 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "gradle" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eba9a359735..d3ea759f3db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,9 +20,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: temurin java-version: '17' @@ -44,7 +44,7 @@ jobs: - name: Run Gradle run: ./gradlew -PskipHandbook=1 && ./gradlew jar -PskipHandbook=1 - name: Upload build - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Grasscutter path: grasscutter-*.jar diff --git a/build.gradle b/build.gradle index 1a6a216e1c0..eca198d36d5 100644 --- a/build.gradle +++ b/build.gradle @@ -76,13 +76,13 @@ dependencies { implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.5.8' // Logging libraries. - implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.7' - implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.4.7' + implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.13' + implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.5.6' implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.7' // Line reading libraries. implementation group: 'org.jline', name: 'jline', version: '3.21.0' - implementation group: 'org.jline', name: 'jline-terminal-jna', version: '3.21.0' + implementation group: 'org.jline', name: 'jline-terminal-jna', version: '3.26.1' implementation group: 'net.java.dev.jna', name: 'jna', version: '5.10.0' // Java Netty for networking. @@ -96,7 +96,7 @@ dependencies { implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.19.6' implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.2' - implementation platform('com.fasterxml.jackson:jackson-bom:2.14.0') + implementation platform('com.fasterxml.jackson:jackson-bom:2.17.1') implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.2' // Reflections libraries. @@ -121,7 +121,7 @@ dependencies { // Java HTTP server library. implementation group: 'io.javalin', name: 'javalin', version: '5.5.0' // Java WebSocket server & client library. - implementation group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.5.2' + implementation group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.5.6' // Google Protocol Buffer definitions. // These are the raw '.proto' files. @@ -130,7 +130,7 @@ dependencies { // Testing libraries. testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.2' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.2' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.2' // HTTP client library for testing. testImplementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0' @@ -261,7 +261,7 @@ clean { protobuf { protoc { // The artifact spec for the Protobuf Compiler - artifact = 'com.google.protobuf:protoc:3.18.1' + artifact = 'com.google.protobuf:protoc:4.27.1' } generatedFilesBaseDir = "$projectDir/src/generated/" diff --git a/src/main/java/emu/grasscutter/DebugConstants.java b/src/main/java/emu/grasscutter/DebugConstants.java index 474db035f77..1338fcbc7bc 100644 --- a/src/main/java/emu/grasscutter/DebugConstants.java +++ b/src/main/java/emu/grasscutter/DebugConstants.java @@ -1,12 +1,12 @@ package emu.grasscutter; public final class DebugConstants { - public static boolean LOG_ABILITIES = false; - public static boolean LOG_LUA_SCRIPTS = false; - public static boolean LOG_QUEST_START = false; - public static boolean LOG_MISSING_ABILITIES = false; - public static boolean LOG_MISSING_LUA_SCRIPTS = false; - public static boolean LOG_MISSING_ABILITY_HANDLERS = false; + public static final boolean LOG_ABILITIES = false; + public static final boolean LOG_LUA_SCRIPTS = false; + public static final boolean LOG_QUEST_START = false; + public static final boolean LOG_MISSING_ABILITIES = false; + public static final boolean LOG_MISSING_LUA_SCRIPTS = false; + public static final boolean LOG_MISSING_ABILITY_HANDLERS = false; /** * WARNING: THIS IS A DANGEROUS SETTING. DO NOT ENABLE UNLESS YOU KNOW WHAT YOU ARE DOING. This diff --git a/src/main/java/emu/grasscutter/GameConstants.java b/src/main/java/emu/grasscutter/GameConstants.java index 8923b338068..30a4ce31eae 100644 --- a/src/main/java/emu/grasscutter/GameConstants.java +++ b/src/main/java/emu/grasscutter/GameConstants.java @@ -7,8 +7,8 @@ import java.util.Arrays; public final class GameConstants { - public static String VERSION = "4.0.0"; - public static int[] VERSION_PARTS = {4, 0, 0}; + public static final String VERSION = "4.0.0"; + public static final int[] VERSION_PARTS = {4, 0, 0}; public static boolean DEBUG = false; public static final int DEFAULT_TEAMS = 4; diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 8c3248dd7c2..7717871b131 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -312,7 +312,7 @@ public static LineReader getConsole() { public static void updateDayOfWeek() { Calendar calendar = Calendar.getInstance(); Grasscutter.currentDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); - logger.debug("Set day of week to " + currentDayOfWeek); + logger.debug("Set day of week to {}", currentDayOfWeek); } public static void startConsole() { diff --git a/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java b/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java index 1892d45046e..eceae40ccc8 100644 --- a/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java +++ b/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java @@ -103,7 +103,7 @@ public LoginResultJson authenticate(AuthenticationRequest request) { KeyFactory keyFactory = KeyFactory.getInstance("RSA"); RSAPrivateKey private_key = (RSAPrivateKey) keyFactory.generatePrivate(keySpec); - Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); cipher.init(Cipher.DECRYPT_MODE, private_key); diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index d452cc6ba11..ffa66fa7b14 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -53,7 +53,7 @@ private static int getUidFromString(String input) { * @return Instance chaining. */ public CommandMap registerCommand(String label, CommandHandler command) { - Grasscutter.getLogger().trace("Registered command: " + label); + Grasscutter.getLogger().trace("Registered command: {}", label); label = label.toLowerCase(); // Get command data. @@ -76,7 +76,7 @@ public CommandMap registerCommand(String label, CommandHandler command) { * @return Instance chaining. */ public CommandMap unregisterCommand(String label) { - Grasscutter.getLogger().trace("Un-registered command: " + label); + Grasscutter.getLogger().trace("Un-registered command: {}", label); CommandHandler handler = this.commands.get(label); if (handler == null) return this; @@ -231,14 +231,12 @@ public void invoke(Player player, Player targetPlayer, String rawMessage) { if (player != null) { Grasscutter.getLogger() .info( - "Command used by [" - + player.getAccount().getUsername() - + " (Player UID: " - + player.getUid() - + ")]: " - + rawMessage); + "Command used by [{} (Player UID: {})]: {}", + player.getAccount().getUsername(), + player.getUid(), + rawMessage); } else { - Grasscutter.getLogger().info("Command used by server console: " + rawMessage); + Grasscutter.getLogger().info("Command used by server console: {}", rawMessage); } } @@ -350,11 +348,12 @@ private void scan() { this.registerCommand(cmdData.label(), (CommandHandler) object); else Grasscutter.getLogger() - .error("Class " + annotated.getName() + " is not a CommandHandler!"); + .error("Class {} is not a CommandHandler!", annotated.getName()); } catch (Exception exception) { Grasscutter.getLogger() .error( - "Failed to register command handler for " + annotated.getSimpleName(), + "Failed to register command handler for {}", + annotated.getSimpleName(), exception); } }); diff --git a/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java b/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java index 85603931d0c..90b202982b1 100644 --- a/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AchievementCommand.java @@ -69,7 +69,7 @@ private static void revokeAll(Player sender, Player targetPlayer, Achievements a @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() < 1) { + if (args.isEmpty()) { this.sendUsageMessage(sender); return; } @@ -88,7 +88,7 @@ public void execute(Player sender, Player targetPlayer, List args) { private void grant( Player sender, Player targetPlayer, Achievements achievements, List args) { - if (args.size() < 1) { + if (args.isEmpty()) { this.sendUsageMessage(sender); } @@ -109,7 +109,7 @@ private void grant( private void revoke( Player sender, Player targetPlayer, Achievements achievements, List args) { - if (args.size() < 1) { + if (args.isEmpty()) { this.sendUsageMessage(sender); } @@ -136,20 +136,19 @@ private void progress( parseInt(args.remove(0)) .ifPresentOrElse( - integer -> { - parseInt(args.remove(0)) - .ifPresentOrElse( - progress -> { - var ret = achievements.progress(integer, progress); - switch (ret.getRet()) { - case SUCCESS -> sendSuccessMessage( - sender, "progress", targetPlayer.getNickname(), integer, progress); - case ACHIEVEMENT_NOT_FOUND -> CommandHandler.sendTranslatedMessage( - sender, ret.getRet().getKey()); - } - }, - () -> this.sendUsageMessage(sender)); - }, + integer -> + parseInt(args.remove(0)) + .ifPresentOrElse( + progress -> { + var ret = achievements.progress(integer, progress); + switch (ret.getRet()) { + case SUCCESS -> sendSuccessMessage( + sender, "progress", targetPlayer.getNickname(), integer, progress); + case ACHIEVEMENT_NOT_FOUND -> CommandHandler.sendTranslatedMessage( + sender, ret.getRet().getKey()); + } + }, + () -> this.sendUsageMessage(sender)), () -> this.sendUsageMessage(sender)); } } diff --git a/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java b/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java index 9cd76ba1347..9433a8a57dc 100644 --- a/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java @@ -19,7 +19,7 @@ public final class AnnounceCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { var manager = Grasscutter.getGameServer().getAnnouncementSystem(); - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } diff --git a/src/main/java/emu/grasscutter/command/commands/ClearCommand.java b/src/main/java/emu/grasscutter/command/commands/ClearCommand.java index 792ce1b3b11..ff2cf4c2c32 100644 --- a/src/main/java/emu/grasscutter/command/commands/ClearCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ClearCommand.java @@ -51,7 +51,7 @@ public void execute(Player sender, Player targetPlayer, List args) { // Extract any tagged int arguments (e.g. "lv90", "x100", "r5") parseIntParameters(args, param, intCommandHandlers); - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } @@ -93,9 +93,10 @@ public void execute(Player sender, Player targetPlayer, List args) { } } + @Setter private static class ClearItemParameters { - @Setter public int lvl = 1; - @Setter public int refinement = 1; - @Setter public int rank = 4; + public int lvl = 1; + public int refinement = 1; + public int rank = 4; } } diff --git a/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java b/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java index c61923452b6..6bce736f8ae 100644 --- a/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java @@ -16,7 +16,7 @@ public final class EnterDungeonCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java index d5134af3432..67c06a4b3f0 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -3,16 +3,23 @@ import static emu.grasscutter.GameConstants.*; import static emu.grasscutter.command.CommandHelpers.*; -import emu.grasscutter.command.*; -import emu.grasscutter.data.*; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameDepot; import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.avatar.AvatarData; -import emu.grasscutter.data.excels.reliquary.*; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.inventory.*; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.*; -import java.util.*; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.props.FightProperty; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.function.BiConsumer; import java.util.regex.Pattern; import lombok.Setter; @@ -279,7 +286,7 @@ private GiveItemParameters parseArgs(Player sender, List args) parseIntParameters(args, param, intCommandHandlers); // At this point, first remaining argument MUST be itemId/avatarId - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar throw new IllegalArgumentException(); } @@ -362,7 +369,7 @@ else if ((param.id > 1000) && (param.id < 1100)) @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() < 1) { // *No args* + if (args.isEmpty()) { // *No args* sendUsageMessage(sender); return; } diff --git a/src/main/java/emu/grasscutter/command/commands/GroupCommand.java b/src/main/java/emu/grasscutter/command/commands/GroupCommand.java index 97359285fb6..4e44ec558a9 100644 --- a/src/main/java/emu/grasscutter/command/commands/GroupCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GroupCommand.java @@ -63,9 +63,7 @@ public void execute(Player sender, Player targetPlayer, List args) { CommandHandler.sendMessage(sender, translate(sender, "commands.group.refreshed", groupId)); } - default -> { - sendUsageMessage(sender); - } + default -> sendUsageMessage(sender); } } } diff --git a/src/main/java/emu/grasscutter/command/commands/ListCommand.java b/src/main/java/emu/grasscutter/command/commands/ListCommand.java index ce0259e091b..a4831eed695 100644 --- a/src/main/java/emu/grasscutter/command/commands/ListCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ListCommand.java @@ -19,14 +19,14 @@ public void execute(Player sender, Player targetPlayer, List args) { Map playersMap = Grasscutter.getGameServer().getPlayers(); boolean needUID = false; - if (args.size() > 0) { + if (!args.isEmpty()) { needUID = args.get(0).equals("uid"); } CommandHandler.sendMessage( sender, translate(sender, "commands.list.success", playersMap.size())); - if (playersMap.size() != 0) { + if (!playersMap.isEmpty()) { StringBuilder playerSet = new StringBuilder(); boolean finalNeedUID = needUID; diff --git a/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java b/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java index acecf334d2b..1ea37f8b75b 100644 --- a/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java @@ -18,7 +18,7 @@ public final class ResetConstCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) { + if (!args.isEmpty() && args.get(0).equalsIgnoreCase("all")) { targetPlayer.getAvatars().forEach(this::resetConstellation); CommandHandler.sendMessage(sender, translate(sender, "commands.resetConst.reset_all")); } else { diff --git a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java index bf4d962464d..5f21dae4a58 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java @@ -24,8 +24,7 @@ public final class SendMailCommand implements CommandHandler { // the command system (again). For now this will do // Key = User that is constructing the mail. - private static final HashMap mailBeingConstructed = - new HashMap(); + private static final HashMap mailBeingConstructed = new HashMap<>(); // Yes this is awful and I hate it. @Override @@ -69,7 +68,7 @@ public void execute(Player sender, Player targetPlayer, List args) { } else { MailBuilder mailBuilder = mailBeingConstructed.get(senderId); - if (args.size() >= 1) { + if (!args.isEmpty()) { switch (args.get(0).toLowerCase()) { case "stop" -> { mailBeingConstructed.remove(senderId); @@ -106,14 +105,12 @@ public void execute(Player sender, Player targetPlayer, List args) { getConstructionArgs(mailBuilder.constructionStage, sender))); } } - case "help" -> { - CommandHandler.sendMessage( - sender, - translate( - sender, - "commands.sendMail.please_use", - getConstructionArgs(mailBuilder.constructionStage, sender))); - } + case "help" -> CommandHandler.sendMessage( + sender, + translate( + sender, + "commands.sendMail.please_use", + getConstructionArgs(mailBuilder.constructionStage, sender))); default -> { switch (mailBuilder.constructionStage) { case 0 -> { diff --git a/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java index cae221176fc..69d46e10302 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java @@ -17,7 +17,7 @@ public final class SendMessageCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() == 0) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } diff --git a/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java b/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java index 1e0edd2648b..a8debd4e65b 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetConstCommand.java @@ -17,7 +17,7 @@ public final class SetConstCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } diff --git a/src/main/java/emu/grasscutter/command/commands/SetPropCommand.java b/src/main/java/emu/grasscutter/command/commands/SetPropCommand.java index 6cd5b0f141b..992899c1e54 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetPropCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetPropCommand.java @@ -291,9 +291,9 @@ enum PseudoProp { } static class Prop { - String name; - PlayerProperty prop; - PseudoProp pseudoProp; + final String name; + final PlayerProperty prop; + final PseudoProp pseudoProp; public Prop(PlayerProperty prop) { this(prop.toString(), prop, PseudoProp.NONE); diff --git a/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java b/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java index fb743f0f8f0..70e7fc6c224 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java @@ -95,9 +95,8 @@ private void unlockAllSceneTags(Player targetPlayer) { // Only remove for big world as some other scenes only have defaults .filter(sceneTag -> sceneTag.getSceneId() == 3) .forEach( - sceneTag -> { - targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId()); - }); + sceneTag -> + targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId())); this.setSceneTags(targetPlayer); } diff --git a/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java b/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java index f8823992636..1cc63d35c0f 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java @@ -171,8 +171,8 @@ private enum Action { } private static class Stat { - String name; - FightProperty prop; + final String name; + final FightProperty prop; public Stat(FightProperty prop) { this.name = prop.toString(); diff --git a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java index d62f8b8542e..a8a0f13e2a0 100644 --- a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java @@ -49,7 +49,7 @@ public void execute(Player sender, Player targetPlayer, List args) { parseIntParameters(args, param, intCommandHandlers); // At this point, first remaining argument MUST be the id and the rest the pos - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar throw new IllegalArgumentException(); } diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index ff71be1bffb..fb071e56425 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -27,7 +27,7 @@ private void setTalentLevel(Player sender, Avatar avatar, int skillId, int newLe @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() < 1) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } @@ -45,9 +45,7 @@ public void execute(Player sender, Player targetPlayer, List args) { String cmdSwitch = args.get(0).toLowerCase(); switch (cmdSwitch) { - default -> { - sendUsageMessage(sender); - } + default -> sendUsageMessage(sender); case "set" -> { if (args.size() < 3) { sendUsageMessage(sender); diff --git a/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java b/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java index d375f490dff..46382bf9d7d 100644 --- a/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TrialAvatarActivityCommand.java @@ -131,7 +131,7 @@ public void execute(Player sender, Player targetPlayer, List args) { translate( sender, "commands.trialAvatarActivity.success_reward", Integer.parseInt(param))); } else { - if (!param.toLowerCase().equals("all")) { + if (!param.equalsIgnoreCase("all")) { CommandHandler.sendMessage( sender, translate(sender, "commands.trialAvatarActivity.invalid_param")); return; diff --git a/src/main/java/emu/grasscutter/config/ConfigContainer.java b/src/main/java/emu/grasscutter/config/ConfigContainer.java index 2b6d20978c5..1cb60fe910a 100644 --- a/src/main/java/emu/grasscutter/config/ConfigContainer.java +++ b/src/main/java/emu/grasscutter/config/ConfigContainer.java @@ -78,11 +78,11 @@ public static void updateConfig() { } } - public Structure folderStructure = new Structure(); - public Database databaseInfo = new Database(); - public Language language = new Language(); - public Account account = new Account(); - public Server server = new Server(); + public final Structure folderStructure = new Structure(); + public final Database databaseInfo = new Database(); + public final Language language = new Language(); + public final Account account = new Account(); + public final Server server = new Server(); // DO NOT. TOUCH. THE VERSION NUMBER. public int version = version(); @@ -90,99 +90,99 @@ public static void updateConfig() { /* Option containers. */ public static class Database { - public DataStore server = new DataStore(); - public DataStore game = new DataStore(); + public final DataStore server = new DataStore(); + public final DataStore game = new DataStore(); public static class DataStore { - public String connectionUri = "mongodb://localhost:27017"; - public String collection = "grasscutter"; + public final String connectionUri = "mongodb://localhost:27017"; + public final String collection = "grasscutter"; } } public static class Structure { - public String resources = "./resources/"; - public String data = "./data/"; - public String packets = "./packets/"; - public String scripts = "resources:Scripts/"; - public String plugins = "./plugins/"; - public String cache = "./cache/"; + public final String resources = "./resources/"; + public final String data = "./data/"; + public final String packets = "./packets/"; + public final String scripts = "resources:Scripts/"; + public final String plugins = "./plugins/"; + public final String cache = "./cache/"; // UNUSED (potentially added later?) // public String dumps = "./dumps/"; } public static class Server { - public Set debugWhitelist = Set.of(); - public Set debugBlacklist = Set.of(); - public ServerRunMode runMode = ServerRunMode.HYBRID; - public boolean logCommands = false; + public final Set debugWhitelist = Set.of(); + public final Set debugBlacklist = Set.of(); + public final ServerRunMode runMode = ServerRunMode.HYBRID; + public final boolean logCommands = false; /** * If enabled, the 'require' Lua function will load the script's compiled varient into the context. (faster; doesn't work as well) * If disabled, all 'require' calls will be replaced with the referenced script's source. (slower; works better) */ - public boolean fastRequire = true; + public final boolean fastRequire = true; - public HTTP http = new HTTP(); - public Game game = new Game(); + public final HTTP http = new HTTP(); + public final Game game = new Game(); - public Dispatch dispatch = new Dispatch(); - public DebugMode debugMode = new DebugMode(); + public final Dispatch dispatch = new Dispatch(); + public final DebugMode debugMode = new DebugMode(); } public static class Language { public Locale language = Locale.getDefault(); - public Locale fallback = Locale.US; - public String document = "EN"; + public final Locale fallback = Locale.US; + public final String document = "EN"; } public static class Account { - public boolean autoCreate = false; - public boolean EXPERIMENTAL_RealPassword = false; - public String[] defaultPermissions = {}; - public String playerEmail = "grasscutter.io"; - public int maxPlayer = -1; + public final boolean autoCreate = false; + public final boolean EXPERIMENTAL_RealPassword = false; + public final String[] defaultPermissions = {}; + public final String playerEmail = "grasscutter.io"; + public final int maxPlayer = -1; } /* Server options. */ public static class HTTP { /* This starts the HTTP server before the game server. */ - public boolean startImmediately = false; + public final boolean startImmediately = false; - public String bindAddress = "0.0.0.0"; - public int bindPort = 443; + public final String bindAddress = "0.0.0.0"; + public final int bindPort = 443; /* This is the address used in URLs. */ - public String accessAddress = "127.0.0.1"; + public final String accessAddress = "127.0.0.1"; /* This is the port used in URLs. */ - public int accessPort = 0; + public final int accessPort = 0; - public Encryption encryption = new Encryption(); - public Policies policies = new Policies(); - public Files files = new Files(); + public final Encryption encryption = new Encryption(); + public final Policies policies = new Policies(); + public final Files files = new Files(); } public static class Game { - public String bindAddress = "0.0.0.0"; - public int bindPort = 22102; + public final String bindAddress = "0.0.0.0"; + public final int bindPort = 22102; /* This is the address used in the default region. */ - public String accessAddress = "127.0.0.1"; + public final String accessAddress = "127.0.0.1"; /* This is the port used in the default region. */ - public int accessPort = 0; + public final int accessPort = 0; /* Enabling this will generate a unique packet encryption key for each player. */ - public boolean useUniquePacketKey = true; + public final boolean useUniquePacketKey = true; /* Entities within a certain range will be loaded for the player */ - public int loadEntitiesForPlayerRange = 300; + public final int loadEntitiesForPlayerRange = 300; /* Start in 'unstable-quests', Lua scripts will be enabled by default. */ - public boolean enableScriptInBigWorld = true; + public final boolean enableScriptInBigWorld = true; public boolean enableConsole = true; /* Kcp internal work interval (milliseconds) */ - public int kcpInterval = 20; + public final int kcpInterval = 20; /* Controls whether packets should be logged in console or not */ public ServerDebugMode logPackets = ServerDebugMode.NONE; /* Show packet payload in console or no (in any case the payload is shown in encrypted view) */ @@ -190,13 +190,13 @@ public static class Game { /* Show annoying loop packets or no */ public boolean isShowLoopPackets = false; - public boolean cacheSceneEntitiesEveryRun = false; + public final boolean cacheSceneEntitiesEveryRun = false; - public GameOptions gameOptions = new GameOptions(); - public JoinOptions joinOptions = new JoinOptions(); - public ConsoleAccount serverAccount = new ConsoleAccount(); + public final GameOptions gameOptions = new GameOptions(); + public final JoinOptions joinOptions = new JoinOptions(); + public final ConsoleAccount serverAccount = new ConsoleAccount(); - public VisionOptions[] visionOptions = new VisionOptions[] { + public final VisionOptions[] visionOptions = new VisionOptions[] { new VisionOptions("VISION_LEVEL_NORMAL" , 80 , 20), new VisionOptions("VISION_LEVEL_LITTLE_REMOTE" , 16 , 40), new VisionOptions("VISION_LEVEL_REMOTE" , 1000 , 250), @@ -210,17 +210,17 @@ public static class Game { public static class Dispatch { /* An array of servers. */ - public List regions = List.of(); + public final List regions = List.of(); /* The URL used to make HTTP requests to the dispatch server. */ - public String dispatchUrl = "ws://127.0.0.1:1111"; + public final String dispatchUrl = "ws://127.0.0.1:1111"; /* A unique key used for encryption. */ - public byte[] encryptionKey = Crypto.createSessionKey(32); + public final byte[] encryptionKey = Crypto.createSessionKey(32); /* A unique key used for authentication. */ - public String dispatchKey = Utils.base64Encode( + public final String dispatchKey = Utils.base64Encode( Crypto.createSessionKey(32)); - public String defaultName = "Grasscutter"; + public final String defaultName = "Grasscutter"; /* Controls whether http requests should be logged in console or not */ public ServerDebugMode logRequests = ServerDebugMode.NONE; @@ -230,127 +230,127 @@ public static class Dispatch { * (see StartupArguments.enableDebug) */ public static class DebugMode { /* Log level of the main server code (works only with -debug arg) */ - public Level serverLoggerLevel = Level.DEBUG; + public final Level serverLoggerLevel = Level.DEBUG; /* Log level of the third-party services (works only with -debug arg): javalin, quartz, reflections, jetty, mongodb.driver */ - public Level servicesLoggersLevel = Level.INFO; + public final Level servicesLoggersLevel = Level.INFO; /* Controls whether packets should be logged in console or not */ - public ServerDebugMode logPackets = ServerDebugMode.ALL; + public final ServerDebugMode logPackets = ServerDebugMode.ALL; /* Show packet payload in console or no (in any case the payload is shown in encrypted view) */ - public boolean isShowPacketPayload = false; + public final boolean isShowPacketPayload = false; /* Show annoying loop packets or no */ - public boolean isShowLoopPackets = false; + public final boolean isShowLoopPackets = false; /* Controls whether http requests should be logged in console or not */ - public ServerDebugMode logRequests = ServerDebugMode.ALL; + public final ServerDebugMode logRequests = ServerDebugMode.ALL; } public static class Encryption { public boolean useEncryption = true; /* Should 'https' be appended to URLs? */ public boolean useInRouting = true; - public String keystore = "./keystore.p12"; - public String keystorePassword = "123456"; + public final String keystore = "./keystore.p12"; + public final String keystorePassword = "123456"; } public static class Policies { - public Policies.CORS cors = new Policies.CORS(); + public final Policies.CORS cors = new Policies.CORS(); public static class CORS { - public boolean enabled = true; - public String[] allowedOrigins = new String[]{"*"}; + public final boolean enabled = true; + public final String[] allowedOrigins = new String[]{"*"}; } } public static class GameOptions { - public InventoryLimits inventoryLimits = new InventoryLimits(); - public AvatarLimits avatarLimits = new AvatarLimits(); - public int sceneEntityLimit = 1000; // Unenforced. TODO: Implement. + public final InventoryLimits inventoryLimits = new InventoryLimits(); + public final AvatarLimits avatarLimits = new AvatarLimits(); + public final int sceneEntityLimit = 1000; // Unenforced. TODO: Implement. - public boolean watchGachaConfig = false; - public boolean enableShopItems = true; - public boolean staminaUsage = true; - public boolean energyUsage = true; - public boolean fishhookTeleport = true; - public boolean trialCostumes = false; + public final boolean watchGachaConfig = false; + public final boolean enableShopItems = true; + public final boolean staminaUsage = true; + public final boolean energyUsage = true; + public final boolean fishhookTeleport = true; + public final boolean trialCostumes = false; @SerializedName(value = "questing", alternate = "questOptions") - public Questing questing = new Questing(); - public ResinOptions resinOptions = new ResinOptions(); - public Rates rates = new Rates(); + public final Questing questing = new Questing(); + public final ResinOptions resinOptions = new ResinOptions(); + public final Rates rates = new Rates(); - public HandbookOptions handbook = new HandbookOptions(); + public final HandbookOptions handbook = new HandbookOptions(); public static class InventoryLimits { - public int weapons = 2000; - public int relics = 2000; - public int materials = 2000; - public int furniture = 2000; - public int all = 30000; + public final int weapons = 2000; + public final int relics = 2000; + public final int materials = 2000; + public final int furniture = 2000; + public final int all = 30000; } public static class AvatarLimits { - public int singlePlayerTeam = 4; - public int multiplayerTeam = 4; + public final int singlePlayerTeam = 4; + public final int multiplayerTeam = 4; } public static class Rates { - public float adventureExp = 1.0f; + public final float adventureExp = 1.0f; public float mora = 1.0f; public float leyLines = 1.0f; } public static class ResinOptions { - public boolean resinUsage = false; - public int cap = 160; - public int rechargeTime = 480; + public final boolean resinUsage = false; + public final int cap = 160; + public final int rechargeTime = 480; } public static class Questing { /* Should questing behavior be used? */ - public boolean enabled = true; + public final boolean enabled = true; } public static class HandbookOptions { - public boolean enable = false; - public boolean allowCommands = true; + public final boolean enable = false; + public final boolean allowCommands = true; - public Limits limits = new Limits(); - public Server server = new Server(); + public final Limits limits = new Limits(); + public final Server server = new Server(); public static class Limits { /* Are rate limits checked? */ - public boolean enabled = false; + public final boolean enabled = false; /* The time for limits to expire. */ - public int interval = 3; + public final int interval = 3; /* The maximum amount of normal requests. */ - public int maxRequests = 10; + public final int maxRequests = 10; /* The maximum amount of entities to be spawned in one request. */ - public int maxEntities = 25; + public final int maxEntities = 25; } public static class Server { /* Are the server settings sent to the handbook? */ - public boolean enforced = false; + public final boolean enforced = false; /* The default server address for the handbook's authentication. */ - public String address = "127.0.0.1"; + public final String address = "127.0.0.1"; /* The default server port for the handbook's authentication. */ - public int port = 443; + public final int port = 443; /* Should the defaults be enforced? */ - public boolean canChange = true; + public final boolean canChange = true; } } } public static class VisionOptions { - public String name; - public int visionRange; - public int gridWidth; + public final String name; + public final int visionRange; + public final int gridWidth; public VisionOptions(String name, int visionRange, int gridWidth) { this.name = name; @@ -360,21 +360,21 @@ public VisionOptions(String name, int visionRange, int gridWidth) { } public static class JoinOptions { - public int[] welcomeEmotes = {2007, 1002, 4010}; - public String welcomeMessage = "Welcome to a Grasscutter server."; - public JoinOptions.Mail welcomeMail = new JoinOptions.Mail(); + public final int[] welcomeEmotes = {2007, 1002, 4010}; + public final String welcomeMessage = "Welcome to a Grasscutter server."; + public final JoinOptions.Mail welcomeMail = new JoinOptions.Mail(); public static class Mail { - public String title = "Welcome to Grasscutter!"; - public String content = """ + public final String title = "Welcome to Grasscutter!"; + public final String content = """ Hi there!\r First of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! \r \r Check out our:\r """; - public String sender = "Lawnmower"; - public emu.grasscutter.game.mail.Mail.MailItem[] items = { + public final String sender = "Lawnmower"; + public final emu.grasscutter.game.mail.Mail.MailItem[] items = { new emu.grasscutter.game.mail.Mail.MailItem(13509, 1, 1), new emu.grasscutter.game.mail.Mail.MailItem(201, 99999, 1) }; @@ -382,18 +382,18 @@ public static class Mail { } public static class ConsoleAccount { - public int avatarId = 10000007; - public int nameCardId = 210001; - public int adventureRank = 1; - public int worldLevel = 0; + public final int avatarId = 10000007; + public final int nameCardId = 210001; + public final int adventureRank = 1; + public final int worldLevel = 0; - public String nickName = "Server"; - public String signature = "Welcome to Grasscutter!"; + public final String nickName = "Server"; + public final String signature = "Welcome to Grasscutter!"; } public static class Files { - public String indexFile = "./index.html"; - public String errorFile = "./404.html"; + public final String indexFile = "./index.html"; + public final String errorFile = "./404.html"; } /* Objects. */ diff --git a/src/main/java/emu/grasscutter/data/DataLoader.java b/src/main/java/emu/grasscutter/data/DataLoader.java index e6ea19068f1..8a91fac9db3 100644 --- a/src/main/java/emu/grasscutter/data/DataLoader.java +++ b/src/main/java/emu/grasscutter/data/DataLoader.java @@ -1,10 +1,17 @@ package emu.grasscutter.data; import emu.grasscutter.Grasscutter; -import emu.grasscutter.utils.*; -import java.io.*; -import java.nio.file.*; -import java.util.*; +import emu.grasscutter.utils.FileUtils; +import emu.grasscutter.utils.JsonUtils; +import emu.grasscutter.utils.TsvUtils; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; import lombok.val; public class DataLoader { @@ -15,7 +22,7 @@ public class DataLoader { * * @param resourcePath The path to the data file to be loaded. * @return InputStream of the data file. - * @throws FileNotFoundException + * @throws FileNotFoundException If the file is not found. * @see #load(String, boolean) */ public static InputStream load(String resourcePath) throws FileNotFoundException { @@ -24,22 +31,18 @@ public static InputStream load(String resourcePath) throws FileNotFoundException /** * Creates an input stream reader for a data file. If the file isn't found within the /data - * directory then it will fallback to the default within the jar resources + * directory then it will fall back to the default within the jar resources * * @param resourcePath The path to the data file to be loaded. * @return InputStreamReader of the data file. - * @throws IOException - * @throws FileNotFoundException + * @throws IOException If the file is not found. + * @throws FileNotFoundException If the file is not found. * @see #load(String, boolean) */ - public static InputStreamReader loadReader(String resourcePath) - throws IOException, FileNotFoundException { - try { - InputStream is = load(resourcePath, true); - return new InputStreamReader(is); - } catch (FileNotFoundException exception) { - throw exception; - } + public static InputStreamReader loadReader(String resourcePath) throws IOException { + InputStream is = load(resourcePath, true); + if (is == null) throw new FileNotFoundException("File not found: " + resourcePath); + return new InputStreamReader(is); } /** @@ -49,7 +52,7 @@ public static InputStreamReader loadReader(String resourcePath) * @param useFallback If the file does not exist in the /data directory, should it use the default * file in the jar? * @return InputStream of the data file. - * @throws FileNotFoundException + * @throws FileNotFoundException If the file is not found. */ public static InputStream load(String resourcePath, boolean useFallback) throws FileNotFoundException { @@ -89,7 +92,7 @@ public static Map loadMap( public static List loadTableToList(String resourcePath, Class classType) throws IOException { val path = FileUtils.getDataPathTsjJsonTsv(resourcePath); - Grasscutter.getLogger().trace("Loading data table from: " + path); + Grasscutter.getLogger().trace("Loading data table from: {}", path); return switch (FileUtils.getFileExtension(path)) { case "json" -> JsonUtils.loadToList(path, classType); case "tsj" -> TsvUtils.loadTsjToListSetField(path, classType); @@ -120,10 +123,9 @@ private static void checkAndCopyData(String name) { if (!Files.exists(filePath)) { var root = filePath.getParent(); - if (root.toFile().mkdirs()) - Grasscutter.getLogger().info("Created data folder '" + root + "'"); + if (root.toFile().mkdirs()) Grasscutter.getLogger().info("Created data folder '{}'", root); - Grasscutter.getLogger().debug("Creating default '" + name + "' data"); + Grasscutter.getLogger().debug("Creating default '{}' data", name); FileUtils.copyResource("/defaults/data/" + name, filePath.toString()); } } diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index a1ef20a8e79..96735f346ce 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -569,8 +569,8 @@ public final class GameData { private static final Int2IntMap trialAvatarIndexIdTrialActivityDataDataMap = new Int2IntOpenHashMap(); - private static Map> fetters = new HashMap<>(); - private static Map> shopGoods = new HashMap<>(); + private static final Map> fetters = new HashMap<>(); + private static final Map> shopGoods = new HashMap<>(); // Getters with different names that stay for now public static Int2ObjectMap getMainQuestDataMap() { @@ -630,15 +630,21 @@ public static ScenePointEntry getScenePointEntryById(int sceneId, int pointId) { // Non-nullable value getters public static int getAvatarLevelExpRequired(int level) { - return Optional.ofNullable(avatarLevelDataMap.get(level)).map(d -> d.getExp()).orElse(0); + return Optional.ofNullable(avatarLevelDataMap.get(level)) + .map(AvatarLevelData::getExp) + .orElse(0); } public static int getAvatarFetterLevelExpRequired(int level) { - return Optional.ofNullable(avatarFetterLevelDataMap.get(level)).map(d -> d.getExp()).orElse(0); + return Optional.ofNullable(avatarFetterLevelDataMap.get(level)) + .map(AvatarFetterLevelData::getExp) + .orElse(0); } public static int getRelicExpRequired(int rankLevel, int level) { - return Optional.ofNullable(getRelicLevelData(rankLevel, level)).map(d -> d.getExp()).orElse(0); + return Optional.ofNullable(getRelicLevelData(rankLevel, level)) + .map(ReliquaryLevelData::getExp) + .orElse(0); } // Generic getter @@ -655,7 +661,7 @@ public static Int2ObjectMap getMapByResourceDef(Class resourceDefinition) field.setAccessible(false); } catch (Exception e) { Grasscutter.getLogger() - .error("Error fetching resource map for " + resourceDefinition.getSimpleName(), e); + .error("Error fetching resource map for {}", resourceDefinition.getSimpleName(), e); } return map; @@ -713,8 +719,8 @@ public static Int2ObjectMap getSceneRoutes(int sceneId) { /** * Fetches the trial data * - * @param trialAvatarIndexId - * @return + * @param trialAvatarIndexId The ID of the trial avatar + * @return The trial data for the trial avatar */ @Nullable public static TrialAvatarActivityDataData getTrialAvatarActivityDataByAvatarIndex( int trialAvatarIndexId) { diff --git a/src/main/java/emu/grasscutter/data/GameDepot.java b/src/main/java/emu/grasscutter/data/GameDepot.java index b3c43bb21e3..0d871131853 100644 --- a/src/main/java/emu/grasscutter/data/GameDepot.java +++ b/src/main/java/emu/grasscutter/data/GameDepot.java @@ -13,17 +13,17 @@ public class GameDepot { public static final int[] BLOCK_SIZE = new int[] {50, 500}; // Scales - private static Int2ObjectMap> relicRandomMainPropDepot = + private static final Int2ObjectMap> relicRandomMainPropDepot = new Int2ObjectOpenHashMap<>(); - private static Int2ObjectMap> relicMainPropDepot = + private static final Int2ObjectMap> relicMainPropDepot = new Int2ObjectOpenHashMap<>(); - private static Int2ObjectMap> relicAffixDepot = + private static final Int2ObjectMap> relicAffixDepot = new Int2ObjectOpenHashMap<>(); @Getter @Setter private static Map playerAbilities = new HashMap<>(); @Getter - private static HashMap> spawnLists = + private static final HashMap> spawnLists = new HashMap<>(); @Getter @Setter private static BlossomConfig blossomConfig; @@ -50,7 +50,7 @@ public static void load() { list.add(data); } // Let the server owner know if theyre missing weights - if (relicMainPropDepot.size() == 0 || relicAffixDepot.size() == 0) { + if (relicMainPropDepot.isEmpty() || relicAffixDepot.isEmpty()) { Grasscutter.getLogger() .error( "Relic properties are missing weights! Please check your ReliquaryMainPropExcelConfigData or ReliquaryAffixExcelConfigData files in your ExcelBinOutput folder."); diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index 8a6c9187948..3d14cc4d299 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -63,7 +63,7 @@ public static List> getResourceDefClasses() { private static List>> getResourceDefClassesPrioritySets() { val classes = Grasscutter.reflector.getSubTypesOf(GameResource.class); val priorities = ResourceType.LoadPriority.getInOrder(); - Grasscutter.getLogger().debug("Priorities are " + priorities); + Grasscutter.getLogger().debug("Priorities are {}", priorities); val map = new LinkedHashMap>>(priorities.size()); priorities.forEach(p -> map.put(p, new HashSet<>())); @@ -140,36 +140,35 @@ public static void loadResources(boolean doReload) { getResourceDefClassesPrioritySets() .forEach( - classes -> { - classes.stream() - .parallel() - .unordered() - .forEach( - c -> { - val type = c.getAnnotation(ResourceType.class); - if (type == null) return; - - val map = GameData.getMapByResourceDef(c); - if (map == null) return; - - try { - loadFromResource(c, type, map, doReload); - } catch (Exception e) { - errors.add(Pair.of(Arrays.toString(type.name()), e)); - } - }); - }); + classes -> + classes.stream() + .parallel() + .unordered() + .forEach( + c -> { + val type = c.getAnnotation(ResourceType.class); + if (type == null) return; + + val map = GameData.getMapByResourceDef(c); + if (map == null) return; + + try { + loadFromResource(c, type, map, doReload); + } catch (Exception e) { + errors.add(Pair.of(Arrays.toString(type.name()), e)); + } + })); errors.forEach( pair -> Grasscutter.getLogger() - .error("Error loading resource file: " + pair.left(), pair.right())); + .error("Error loading resource file: {}", pair.left(), pair.right())); long endTime = System.nanoTime(); long ns = (endTime - startTime); // divide by 1000000 to get milliseconds. - Grasscutter.getLogger().debug("Loading resources took " + ns + "ns == " + ns / 1000000 + "ms"); + Grasscutter.getLogger().debug("Loading resources took {}ns == {}ms", ns, ns / 1000000); } @SuppressWarnings("rawtypes") - protected static void loadFromResource( + private static void loadFromResource( Class c, ResourceType type, Int2ObjectMap map, boolean doReload) throws Exception { val simpleName = c.getSimpleName(); if (doReload || !loadedResources.contains(simpleName)) { @@ -181,7 +180,7 @@ protected static void loadFromResource( } @SuppressWarnings({"rawtypes", "unchecked"}) - protected static void loadFromResource(Class c, Path filename, Int2ObjectMap map) + private static void loadFromResource(Class c, Path filename, Int2ObjectMap map) throws Exception { val results = switch (FileUtils.getFileExtension(filename)) { @@ -200,7 +199,7 @@ protected static void loadFromResource(Class c, Path filename, Int2Object } @SuppressWarnings({"rawtypes", "unchecked"}) - protected static void loadFromResource(Class c, String fileName, Int2ObjectMap map) + private static void loadFromResource(Class c, String fileName, Int2ObjectMap map) throws Exception { JsonUtils.loadToList(getResourcePath("ExcelBinOutput/" + fileName), c) .forEach( @@ -283,7 +282,7 @@ private static void loadRoutes() { } }); Grasscutter.getLogger() - .debug("Loaded " + GameData.getSceneNpcBornData().size() + " SceneRouteDatas."); + .debug("Loaded {} SceneRouteDatas.", GameData.getSceneNpcBornData().size()); } catch (IOException e) { Grasscutter.getLogger().error("Failed to load SceneRouteData folder."); } @@ -404,7 +403,7 @@ private static void loadAbilityModifiers(Path path) { .forEach(data -> loadAbilityData(data.Default)); } catch (IOException e) { Grasscutter.getLogger() - .error("Error loading ability modifiers from path " + path.toString() + ": ", e); + .error("Error loading ability modifiers from path {}: ", path.toString(), e); } } @@ -413,7 +412,7 @@ private static void loadAbilityData(AbilityData data) { GameData.getAbilityHashes().put(Utils.abilityHash(data.abilityName), data.abilityName); var modifiers = data.modifiers; - if (modifiers == null || modifiers.size() == 0) return; + if (modifiers == null || modifiers.isEmpty()) return; var name = data.abilityName; var modifierEntry = new AbilityModifierEntry(name); @@ -466,7 +465,7 @@ private static void loadTalent(Path path) { path, String.class, new TypeToken>() {}.getType())); } catch (IOException e) { Grasscutter.getLogger() - .error("Error loading ability modifiers from path " + path.toString() + ": ", e); + .error("Error loading ability modifiers from path {}: ", path.toString(), e); } } @@ -533,7 +532,7 @@ private static void loadOpenConfig() { }); } catch (IOException e) { Grasscutter.getLogger() - .error("Error loading open config: no files found in " + folderName); + .error("Error loading open config: no files found in {}", folderName); return; } } @@ -589,7 +588,7 @@ private static void loadQuests() { } Grasscutter.getLogger() - .debug("Loaded " + GameData.getMainQuestDataMap().size() + " MainQuestDatas."); + .debug("Loaded {} MainQuestDatas.", GameData.getMainQuestDataMap().size()); } public static void loadScriptSceneData() { @@ -607,7 +606,7 @@ public static void loadScriptSceneData() { } }); Grasscutter.getLogger() - .debug("Loaded " + GameData.getScriptSceneDataMap().size() + " ScriptSceneDatas."); + .debug("Loaded {} ScriptSceneDatas.", GameData.getScriptSceneDataMap().size()); } catch (IOException e) { Grasscutter.getLogger().debug("ScriptSceneData folder missing or empty."); } @@ -632,9 +631,8 @@ private static void loadHomeworldDefaultSaveData() { }); Grasscutter.getLogger() .debug( - "Loaded " - + GameData.getHomeworldDefaultSaveData().size() - + " HomeworldDefaultSaveDatas."); + "Loaded {} HomeworldDefaultSaveDatas.", + GameData.getHomeworldDefaultSaveData().size()); } catch (IOException e) { Grasscutter.getLogger().error("Failed to load HomeworldDefaultSave folder."); } @@ -647,7 +645,7 @@ private static void loadNpcBornData() { path -> { try { val data = JsonUtils.loadToClass(path, SceneNpcBornData.class); - if (data.getBornPosList() == null || data.getBornPosList().size() == 0) { + if (data.getBornPosList() == null || data.getBornPosList().isEmpty()) { return; } @@ -659,7 +657,7 @@ private static void loadNpcBornData() { } }); Grasscutter.getLogger() - .debug("Loaded " + GameData.getSceneNpcBornData().size() + " SceneNpcBornDatas."); + .debug("Loaded {} SceneNpcBornDatas.", GameData.getSceneNpcBornData().size()); } catch (IOException e) { Grasscutter.getLogger().error("Failed to load SceneNpcBorn folder."); } @@ -837,7 +835,6 @@ private static void loadSubfieldMappings() { try { JsonUtils.loadToList(getResourcePath("Server/SubfieldMapping.json"), SubfieldMapping.class) .forEach(entry -> subfieldMap.put(entry.getEntityId(), entry)); - ; } catch (IOException | NullPointerException ignored) { } Grasscutter.getLogger().debug("Loaded {} subfield mappings.", subfieldMap.size()); @@ -851,7 +848,6 @@ private static void loadSubfieldMappings() { JsonUtils.loadToList( getResourcePath("Server/DropSubfieldMapping.json"), DropSubfieldMapping.class) .forEach(entry -> dropSubfieldMap.put(entry.getDropId(), entry)); - ; } catch (IOException | NullPointerException ignored) { } Grasscutter.getLogger().debug("Loaded {} drop subfield mappings.", dropSubfieldMap.size()); @@ -866,7 +862,6 @@ private static void loadSubfieldMappings() { getResourcePath("Server/DropTableExcelConfigData.json"), DropTableExcelConfigData.class) .forEach(entry -> dropTableExcelConfigDataMap.put(entry.getId(), entry)); - ; } catch (IOException | NullPointerException ignored) { } Grasscutter.getLogger() diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityEmbryoEntry.java b/src/main/java/emu/grasscutter/data/binout/AbilityEmbryoEntry.java index 43d5471c5f8..c191368e762 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityEmbryoEntry.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityEmbryoEntry.java @@ -1,5 +1,8 @@ package emu.grasscutter.data.binout; +import lombok.Getter; + +@Getter public class AbilityEmbryoEntry { private String name; private String[] abilities; @@ -10,12 +13,4 @@ public AbilityEmbryoEntry(String avatarName, String[] array) { this.name = avatarName; this.abilities = array; } - - public String getName() { - return name; - } - - public String[] getAbilities() { - return abilities; - } } diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityMixinData.java b/src/main/java/emu/grasscutter/data/binout/AbilityMixinData.java index 50388dec364..72030788b60 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityMixinData.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityMixinData.java @@ -3,17 +3,18 @@ import com.google.gson.*; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; +import java.io.Serial; import java.io.Serializable; import java.util.*; public class AbilityMixinData implements Serializable { - private static final long serialVersionUID = -2001232313615923575L; + @Serial private static final long serialVersionUID = -2001232313615923575L; public enum Type { AttachToGadgetStateMixin, AttachToStateIDMixin, ShieldBarMixin, - TileAttackManagerMixin; + TileAttackManagerMixin } @SerializedName("$type") @@ -27,7 +28,7 @@ public List getModifierNames() { List list = (new Gson()).fromJson(modifierName, listType); return list; } else { - return Arrays.asList(modifierName.getAsString()); + return Collections.singletonList(modifierName.getAsString()); } } } diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java index 562616bb4eb..93794481239 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java @@ -3,11 +3,12 @@ import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.common.DynamicFloat; import emu.grasscutter.game.props.ElementType; +import java.io.Serial; import java.io.Serializable; import lombok.ToString; public class AbilityModifier implements Serializable { - private static final long serialVersionUID = -2001232313615923575L; + @Serial private static final long serialVersionUID = -2001232313615923575L; public State state; @@ -264,7 +265,7 @@ public enum Type { TurnDirectionToPos, UpdateReactionDamage, UseSkillEliteSet, - WidgetSkillStart; + WidgetSkillStart } @SerializedName("$type") diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityModifierEntry.java b/src/main/java/emu/grasscutter/data/binout/AbilityModifierEntry.java index 9b519ab9ce9..c829c09366d 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityModifierEntry.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityModifierEntry.java @@ -2,12 +2,13 @@ import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import java.util.*; +import lombok.Getter; public class AbilityModifierEntry { - public List onModifierAdded; - public List onThinkInterval; - public List onRemoved; - private final String name; // Custom value + public final List onModifierAdded; + @Getter public final List onThinkInterval; + @Getter public final List onRemoved; + @Getter private final String name; // Custom value public AbilityModifierEntry(String name) { this.name = name; @@ -16,19 +17,7 @@ public AbilityModifierEntry(String name) { this.onRemoved = new ArrayList<>(); } - public String getName() { - return name; - } - public List getOnAdded() { return onModifierAdded; } - - public List getOnThinkInterval() { - return onThinkInterval; - } - - public List getOnRemoved() { - return onRemoved; - } } diff --git a/src/main/java/emu/grasscutter/data/binout/MainQuestData.java b/src/main/java/emu/grasscutter/data/binout/MainQuestData.java index da7b589c703..6ec95006c3d 100644 --- a/src/main/java/emu/grasscutter/data/binout/MainQuestData.java +++ b/src/main/java/emu/grasscutter/data/binout/MainQuestData.java @@ -5,53 +5,22 @@ import emu.grasscutter.game.quest.enums.QuestType; import java.util.*; import lombok.Data; +import lombok.Getter; public class MainQuestData { - private int id; + @Getter private int id; private int ICLLDPJFIMA; - private int series; - private QuestType type; + @Getter private int series; + @Getter private QuestType type; - private long titleTextMapHash; - private int[] suggestTrackMainQuestList; - private int[] rewardIdList; + @Getter private long titleTextMapHash; + @Getter private int[] suggestTrackMainQuestList; + @Getter private int[] rewardIdList; - private SubQuestData[] subQuests; - private List talks; + @Getter private SubQuestData[] subQuests; + @Getter private List talks; private long[] preloadLuaList; - public int getId() { - return id; - } - - public int getSeries() { - return series; - } - - public QuestType getType() { - return type; - } - - public long getTitleTextMapHash() { - return titleTextMapHash; - } - - public int[] getSuggestTrackMainQuestList() { - return suggestTrackMainQuestList; - } - - public int[] getRewardIdList() { - return rewardIdList; - } - - public SubQuestData[] getSubQuests() { - return subQuests; - } - - public List getTalks() { - return talks; - } - public void onLoad() { if (this.talks == null) this.talks = new ArrayList<>(); if (this.subQuests == null) this.subQuests = new SubQuestData[0]; diff --git a/src/main/java/emu/grasscutter/data/binout/OpenConfigEntry.java b/src/main/java/emu/grasscutter/data/binout/OpenConfigEntry.java index 25f8055bf26..54735a1297c 100644 --- a/src/main/java/emu/grasscutter/data/binout/OpenConfigEntry.java +++ b/src/main/java/emu/grasscutter/data/binout/OpenConfigEntry.java @@ -2,7 +2,9 @@ import emu.grasscutter.data.ResourceLoader.OpenConfigData; import java.util.*; +import lombok.Getter; +@Getter public class OpenConfigEntry { private final String name; private String[] addAbilities; @@ -25,46 +27,23 @@ public OpenConfigEntry(String name, OpenConfigData[] data) { } } - if (abilityList.size() > 0) { + if (!abilityList.isEmpty()) { this.addAbilities = abilityList.toArray(new String[0]); } - if (modList.size() > 0) { + if (!modList.isEmpty()) { this.skillPointModifiers = modList.toArray(new SkillPointModifier[0]); } } - public String getName() { - return name; - } - - public String[] getAddAbilities() { - return addAbilities; - } - - public int getExtraTalentIndex() { - return extraTalentIndex; - } - - public SkillPointModifier[] getSkillPointModifiers() { - return skillPointModifiers; - } - + @Getter public static class SkillPointModifier { - private int skillId; - private int delta; + private final int skillId; + private final int delta; public SkillPointModifier(int skillId, int delta) { this.skillId = skillId; this.delta = delta; } - - public int getSkillId() { - return skillId; - } - - public int getDelta() { - return delta; - } } } diff --git a/src/main/java/emu/grasscutter/data/binout/ScenePointEntry.java b/src/main/java/emu/grasscutter/data/binout/ScenePointEntry.java index 3ca40f32e01..4b9d805b0da 100644 --- a/src/main/java/emu/grasscutter/data/binout/ScenePointEntry.java +++ b/src/main/java/emu/grasscutter/data/binout/ScenePointEntry.java @@ -3,9 +3,10 @@ import emu.grasscutter.data.common.PointData; import lombok.Getter; +@Getter public class ScenePointEntry { - @Getter private final int sceneId; - @Getter private final PointData pointData; + private final int sceneId; + private final PointData pointData; @Deprecated(forRemoval = true) public ScenePointEntry(String name, PointData pointData) { diff --git a/src/main/java/emu/grasscutter/data/binout/TalentData.java b/src/main/java/emu/grasscutter/data/binout/TalentData.java index 29b0b93b48e..ae299402064 100644 --- a/src/main/java/emu/grasscutter/data/binout/TalentData.java +++ b/src/main/java/emu/grasscutter/data/binout/TalentData.java @@ -10,7 +10,7 @@ public enum Type { ModifySkillCD, UnlockTalentParam, AddTalentExtraLevel, - ModifyAbility; + ModifyAbility } @SerializedName("$type") diff --git a/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java b/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java index 9afe5a5d148..fc63f002b2f 100644 --- a/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java +++ b/src/main/java/emu/grasscutter/data/binout/config/ConfigLevelEntity.java @@ -4,13 +4,14 @@ import java.util.List; import lombok.Getter; +@Getter public class ConfigLevelEntity { - @Getter private List abilities; - @Getter private List monsterAbilities; - @Getter private List avatarAbilities; - @Getter private List teamAbilities; - @Getter private List preloadMonsterEntityIDs; + private List abilities; + private List monsterAbilities; + private List avatarAbilities; + private List teamAbilities; + private List preloadMonsterEntityIDs; - @Getter private String dropElemControlType; + private String dropElemControlType; } diff --git a/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java b/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java index cd8287a72d8..4116be5c8f3 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/RotAngleType.java @@ -3,13 +3,14 @@ // import emu.grasscutter.scripts.constants.IntValueEnum; import lombok.Getter; +@Getter public enum RotAngleType /*implements IntValueEnum */ { ROT_NONE(-1), ROT_ANGLE_X(0), ROT_ANGLE_Y(1), ROT_ANGLE_Z(2); - @Getter private final int id; + private final int id; RotAngleType(int id) { this.id = id; diff --git a/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java b/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java index 55b4cd04bc0..558b23e0d4e 100644 --- a/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java +++ b/src/main/java/emu/grasscutter/data/binout/routes/RouteType.java @@ -3,13 +3,14 @@ // import emu.grasscutter.scripts.constants.IntValueEnum; import lombok.Getter; +@Getter public enum RouteType /*implements IntValueEnum*/ { Unknown(-1), OneWay(0), Reciprocate(1), Loop(2); - @Getter private final int id; + private final int id; RouteType(int id) { this.id = id; diff --git a/src/main/java/emu/grasscutter/data/common/CurveInfo.java b/src/main/java/emu/grasscutter/data/common/CurveInfo.java index d9f8147233e..bcc6fd8f5d2 100644 --- a/src/main/java/emu/grasscutter/data/common/CurveInfo.java +++ b/src/main/java/emu/grasscutter/data/common/CurveInfo.java @@ -1,19 +1,10 @@ package emu.grasscutter.data.common; +import lombok.Getter; + +@Getter public class CurveInfo { private String type; private String arith; private float value; - - public String getType() { - return type; - } - - public String getArith() { - return arith; - } - - public float getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/data/common/DynamicFloat.java b/src/main/java/emu/grasscutter/data/common/DynamicFloat.java index 99dc1243396..5a035f63275 100644 --- a/src/main/java/emu/grasscutter/data/common/DynamicFloat.java +++ b/src/main/java/emu/grasscutter/data/common/DynamicFloat.java @@ -92,7 +92,7 @@ public float get(ProudSkillData skill, float defaultValue) { } public static class StackOp { - public Op op; + public final Op op; public float fValue; public String sValue; diff --git a/src/main/java/emu/grasscutter/data/common/FightPropData.java b/src/main/java/emu/grasscutter/data/common/FightPropData.java index cdc634a39c6..9bc31f78171 100644 --- a/src/main/java/emu/grasscutter/data/common/FightPropData.java +++ b/src/main/java/emu/grasscutter/data/common/FightPropData.java @@ -1,24 +1,14 @@ package emu.grasscutter.data.common; import emu.grasscutter.game.props.FightProperty; +import lombok.Getter; +@Getter public class FightPropData { private String propType; private FightProperty prop; private float value; - public String getPropType() { - return propType; - } - - public float getValue() { - return value; - } - - public FightProperty getProp() { - return prop; - } - public void onLoad() { this.prop = FightProperty.getPropByName(propType); } diff --git a/src/main/java/emu/grasscutter/data/common/ItemParamData.java b/src/main/java/emu/grasscutter/data/common/ItemParamData.java index c7723597626..e1d768ae31c 100644 --- a/src/main/java/emu/grasscutter/data/common/ItemParamData.java +++ b/src/main/java/emu/grasscutter/data/common/ItemParamData.java @@ -1,8 +1,10 @@ package emu.grasscutter.data.common; import com.google.gson.annotations.SerializedName; +import lombok.Getter; // Used in excels +@Getter public class ItemParamData { @SerializedName( value = "id", @@ -21,18 +23,10 @@ public ItemParamData(int id, int count) { this.count = count; } - public int getId() { - return id; - } - public int getItemId() { return id; } - public int getCount() { - return count; - } - public int getItemCount() { return count; } diff --git a/src/main/java/emu/grasscutter/data/common/ItemParamStringData.java b/src/main/java/emu/grasscutter/data/common/ItemParamStringData.java index 7f864fc9efc..dbb3cc2daf6 100644 --- a/src/main/java/emu/grasscutter/data/common/ItemParamStringData.java +++ b/src/main/java/emu/grasscutter/data/common/ItemParamStringData.java @@ -1,19 +1,14 @@ package emu.grasscutter.data.common; +import lombok.Getter; + +@Getter public class ItemParamStringData { private int id; private String count; public ItemParamStringData() {} - public int getId() { - return id; - } - - public String getCount() { - return count; - } - public ItemParamData toItemParamData() { if (count.contains(";")) { String[] split = count.split(";"); diff --git a/src/main/java/emu/grasscutter/data/common/ItemUseData.java b/src/main/java/emu/grasscutter/data/common/ItemUseData.java index e1af1a0b267..92341b3257a 100644 --- a/src/main/java/emu/grasscutter/data/common/ItemUseData.java +++ b/src/main/java/emu/grasscutter/data/common/ItemUseData.java @@ -1,10 +1,11 @@ package emu.grasscutter.data.common; import emu.grasscutter.game.props.ItemUseOp; +import lombok.Getter; public class ItemUseData { private ItemUseOp useOp; - private String[] useParam; + @Getter private String[] useParam; public ItemUseOp getUseOp() { if (useOp == null) { @@ -12,8 +13,4 @@ public ItemUseOp getUseOp() { } return useOp; } - - public String[] getUseParam() { - return useParam; - } } diff --git a/src/main/java/emu/grasscutter/data/common/OpenCondData.java b/src/main/java/emu/grasscutter/data/common/OpenCondData.java index 51581f13e1c..e3658a75ee5 100644 --- a/src/main/java/emu/grasscutter/data/common/OpenCondData.java +++ b/src/main/java/emu/grasscutter/data/common/OpenCondData.java @@ -1,24 +1,18 @@ package emu.grasscutter.data.common; import java.util.List; +import lombok.Getter; +@Getter public class OpenCondData { private String condType; private List paramList; - public String getCondType() { - return condType; + public void setCondType(String cType) { + condType = cType; } - public void setCondType(String condType) { - condType = condType; - } - - public List getParamList() { - return paramList; - } - - public void setParamList(List paramList) { - paramList = paramList; + public void setParamList(List pList) { + paramList = pList; } } diff --git a/src/main/java/emu/grasscutter/data/common/PropGrowCurve.java b/src/main/java/emu/grasscutter/data/common/PropGrowCurve.java index d7951917dba..a0e6c1bbeff 100644 --- a/src/main/java/emu/grasscutter/data/common/PropGrowCurve.java +++ b/src/main/java/emu/grasscutter/data/common/PropGrowCurve.java @@ -1,14 +1,9 @@ package emu.grasscutter.data.common; +import lombok.Getter; + +@Getter public class PropGrowCurve { private String type; private String growCurve; - - public String getType() { - return this.type; - } - - public String getGrowCurve() { - return this.growCurve; - } } diff --git a/src/main/java/emu/grasscutter/data/excels/CombineData.java b/src/main/java/emu/grasscutter/data/excels/CombineData.java index b4430558926..430eaefda8d 100644 --- a/src/main/java/emu/grasscutter/data/excels/CombineData.java +++ b/src/main/java/emu/grasscutter/data/excels/CombineData.java @@ -4,21 +4,22 @@ import emu.grasscutter.data.common.ItemParamData; import java.util.List; import java.util.stream.Collectors; +import lombok.Getter; @ResourceType(name = "CombineExcelConfigData.json") public class CombineData extends GameResource { - private int combineId; - private int playerLevel; + @Getter private int combineId; + @Getter private int playerLevel; private boolean isDefaultShow; - private int combineType; - private int subCombineType; - private int resultItemId; - private int resultItemCount; - private int scoinCost; - private List randomItems; - private List materialItems; - private String recipeType; + @Getter private int combineType; + @Getter private int subCombineType; + @Getter private int resultItemId; + @Getter private int resultItemCount; + @Getter private int scoinCost; + @Getter private List randomItems; + @Getter private List materialItems; + @Getter private String recipeType; @Override public int getId() { @@ -35,47 +36,7 @@ public void onLoad() { materialItems.stream().filter(item -> item.getId() > 0).collect(Collectors.toList()); } - public int getCombineId() { - return combineId; - } - - public int getPlayerLevel() { - return playerLevel; - } - public boolean isDefaultShow() { return isDefaultShow; } - - public int getCombineType() { - return combineType; - } - - public int getSubCombineType() { - return subCombineType; - } - - public int getResultItemId() { - return resultItemId; - } - - public int getResultItemCount() { - return resultItemCount; - } - - public int getScoinCost() { - return scoinCost; - } - - public List getRandomItems() { - return randomItems; - } - - public List getMaterialItems() { - return materialItems; - } - - public String getRecipeType() { - return recipeType; - } } diff --git a/src/main/java/emu/grasscutter/data/excels/CookBonusData.java b/src/main/java/emu/grasscutter/data/excels/CookBonusData.java index 1a2de3884cd..b02cb79458e 100644 --- a/src/main/java/emu/grasscutter/data/excels/CookBonusData.java +++ b/src/main/java/emu/grasscutter/data/excels/CookBonusData.java @@ -2,7 +2,9 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.ResourceType.LoadPriority; +import lombok.Getter; +@Getter @ResourceType( name = {"CookBonusExcelConfigData.json"}, loadPriority = LoadPriority.LOW) @@ -17,22 +19,6 @@ public int getId() { return this.avatarId; } - public int getAvatarId() { - return avatarId; - } - - public int getRecipeId() { - return recipeId; - } - - public int[] getParamVec() { - return paramVec; - } - - public int[] getComplexParamVec() { - return complexParamVec; - } - public int getReplacementItemId() { return this.paramVec[0]; } diff --git a/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java b/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java index ebec960cbdd..8c51cfde285 100644 --- a/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/EnvAnimalGatherConfigData.java @@ -3,13 +3,14 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.common.ItemParamData; import java.util.List; +import lombok.Getter; @ResourceType( name = "EnvAnimalGatherExcelConfigData.json", loadPriority = ResourceType.LoadPriority.LOW) public class EnvAnimalGatherConfigData extends GameResource { - private int animalId; - private String entityType; + @Getter private int animalId; + @Getter private String entityType; private List gatherItemId; private String excludeWeathers; private int aliveTime; @@ -21,15 +22,7 @@ public int getId() { return animalId; } - public int getAnimalId() { - return animalId; - } - - public String getEntityType() { - return entityType; - } - public ItemParamData getGatherItem() { - return gatherItemId.size() > 0 ? gatherItemId.get(0) : null; + return !gatherItemId.isEmpty() ? gatherItemId.get(0) : null; } } diff --git a/src/main/java/emu/grasscutter/data/excels/EquipAffixData.java b/src/main/java/emu/grasscutter/data/excels/EquipAffixData.java index 08adc351d9e..d566c422d3a 100644 --- a/src/main/java/emu/grasscutter/data/excels/EquipAffixData.java +++ b/src/main/java/emu/grasscutter/data/excels/EquipAffixData.java @@ -3,17 +3,18 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.common.FightPropData; import java.util.ArrayList; +import lombok.Getter; @ResourceType(name = "EquipAffixExcelConfigData.json") public class EquipAffixData extends GameResource { private int affixId; private int id; - private int level; - private long nameTextMapHash; - private String openConfig; - private FightPropData[] addProps; - private float[] paramList; + @Getter private int level; + @Getter private long nameTextMapHash; + @Getter private String openConfig; + @Getter private FightPropData[] addProps; + @Getter private float[] paramList; @Override public int getId() { @@ -24,29 +25,9 @@ public int getMainId() { return id; } - public int getLevel() { - return level; - } - - public long getNameTextMapHash() { - return nameTextMapHash; - } - - public String getOpenConfig() { - return openConfig; - } - - public FightPropData[] getAddProps() { - return addProps; - } - - public float[] getParamList() { - return paramList; - } - @Override public void onLoad() { - ArrayList parsed = new ArrayList(getAddProps().length); + ArrayList parsed = new ArrayList<>(getAddProps().length); for (FightPropData prop : getAddProps()) { if (prop.getPropType() != null && prop.getValue() != 0f) { prop.onLoad(); diff --git a/src/main/java/emu/grasscutter/data/excels/FetterCharacterCardData.java b/src/main/java/emu/grasscutter/data/excels/FetterCharacterCardData.java index bdd7fa4414a..7b4dce10736 100644 --- a/src/main/java/emu/grasscutter/data/excels/FetterCharacterCardData.java +++ b/src/main/java/emu/grasscutter/data/excels/FetterCharacterCardData.java @@ -2,21 +2,18 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.ResourceType.LoadPriority; +import lombok.Getter; @ResourceType(name = "FetterCharacterCardExcelConfigData.json", loadPriority = LoadPriority.HIGHEST) public class FetterCharacterCardData extends GameResource { private int avatarId; - private int rewardId; + @Getter private int rewardId; @Override public int getId() { return avatarId; } - public int getRewardId() { - return rewardId; - } - @Override public void onLoad() {} } diff --git a/src/main/java/emu/grasscutter/data/excels/FetterData.java b/src/main/java/emu/grasscutter/data/excels/FetterData.java index 08eea561c36..24401a9001e 100644 --- a/src/main/java/emu/grasscutter/data/excels/FetterData.java +++ b/src/main/java/emu/grasscutter/data/excels/FetterData.java @@ -4,6 +4,7 @@ import emu.grasscutter.data.ResourceType.LoadPriority; import emu.grasscutter.data.common.OpenCondData; import java.util.List; +import lombok.Getter; @ResourceType( name = { @@ -15,7 +16,7 @@ }, loadPriority = LoadPriority.HIGHEST) public class FetterData extends GameResource { - private int avatarId; + @Getter private int avatarId; private int fetterId; private List openCond; @@ -24,10 +25,6 @@ public int getId() { return fetterId; } - public int getAvatarId() { - return avatarId; - } - public List getOpenConds() { return openCond; } diff --git a/src/main/java/emu/grasscutter/data/excels/GatherData.java b/src/main/java/emu/grasscutter/data/excels/GatherData.java index a9129be6646..2eca6b64c91 100644 --- a/src/main/java/emu/grasscutter/data/excels/GatherData.java +++ b/src/main/java/emu/grasscutter/data/excels/GatherData.java @@ -1,14 +1,15 @@ package emu.grasscutter.data.excels; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = "GatherExcelConfigData.json") public class GatherData extends GameResource { private int pointType; private int id; - private int gadgetId; - private int itemId; - private int cd; // Probably hours + @Getter private int gadgetId; + @Getter private int itemId; + @Getter private int cd; // Probably hours private boolean isForbidGuest; private boolean initDisableInteract; @@ -21,18 +22,6 @@ public int getGatherId() { return id; } - public int getGadgetId() { - return gadgetId; - } - - public int getItemId() { - return itemId; - } - - public int getCd() { - return cd; - } - public boolean isForbidGuest() { return isForbidGuest; } diff --git a/src/main/java/emu/grasscutter/data/excels/ItemData.java b/src/main/java/emu/grasscutter/data/excels/ItemData.java index de77a4ba623..edce795e1dd 100644 --- a/src/main/java/emu/grasscutter/data/excels/ItemData.java +++ b/src/main/java/emu/grasscutter/data/excels/ItemData.java @@ -24,7 +24,7 @@ public class ItemData extends GameResource { @Getter(onMethod_ = @Override) private int id; - private int stackLimit = 1; + private final int stackLimit = 1; private int maxUseCount; private int rankLevel; private String effectName; @@ -37,7 +37,7 @@ public class ItemData extends GameResource { private int[] destroyReturnMaterialCount; // Enums - private ItemType itemType = ItemType.ITEM_NONE; + private final ItemType itemType = ItemType.ITEM_NONE; private MaterialType materialType = MaterialType.MATERIAL_NONE; private EquipType equipType = EquipType.EQUIP_NONE; private String effectType; @@ -48,10 +48,10 @@ public class ItemData extends GameResource { private int[] satiationParams; // Usable item - private ItemUseTarget useTarget = ItemUseTarget.ITEM_USE_TARGET_NONE; + private final ItemUseTarget useTarget = ItemUseTarget.ITEM_USE_TARGET_NONE; private List itemUse; private List itemUseActions; - private boolean useOnGain = false; + private final boolean useOnGain = false; // Relic private int mainPropDepotId; @@ -79,7 +79,7 @@ public class ItemData extends GameResource { private int comfort; private List furnType; private List furnitureGadgetID; - private SpecialFurnitureType specialFurnitureType = SpecialFurnitureType.NOT_SPECIAL; + private final SpecialFurnitureType specialFurnitureType = SpecialFurnitureType.NOT_SPECIAL; @SerializedName( value = "roomSceneId", diff --git a/src/main/java/emu/grasscutter/data/excels/OpenStateData.java b/src/main/java/emu/grasscutter/data/excels/OpenStateData.java index 9d8d187c386..6c4dc0cdba8 100644 --- a/src/main/java/emu/grasscutter/data/excels/OpenStateData.java +++ b/src/main/java/emu/grasscutter/data/excels/OpenStateData.java @@ -39,12 +39,10 @@ public enum OpenStateCondType { OPEN_STATE_COND_PARENT_QUEST } + @Getter public static class OpenStateCond { - @Getter private OpenStateCondType condType; - @Getter private int param; - @Getter private int param2; } } diff --git a/src/main/java/emu/grasscutter/data/excels/PlayerLevelData.java b/src/main/java/emu/grasscutter/data/excels/PlayerLevelData.java index 35632c99084..59da00fe7ec 100644 --- a/src/main/java/emu/grasscutter/data/excels/PlayerLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/PlayerLevelData.java @@ -9,7 +9,7 @@ public class PlayerLevelData extends GameResource { private int level; private int exp; private int rewardId; - private int expeditionLimitAdd = 0; + private final int expeditionLimitAdd = 0; private int unlockWorldLevel; private long unlockDescTextMapHash; diff --git a/src/main/java/emu/grasscutter/data/excels/ProudSkillData.java b/src/main/java/emu/grasscutter/data/excels/ProudSkillData.java index 51d4ae2887a..671e712a872 100644 --- a/src/main/java/emu/grasscutter/data/excels/ProudSkillData.java +++ b/src/main/java/emu/grasscutter/data/excels/ProudSkillData.java @@ -25,7 +25,8 @@ public class ProudSkillData extends GameResource { @Getter private long nameTextMapHash; @Transient private Iterable totalCostItems; - @Transient @Getter private Object2FloatMap paramListMap = new Object2FloatOpenHashMap<>(); + @Transient @Getter + private final Object2FloatMap paramListMap = new Object2FloatOpenHashMap<>(); @Override public int getId() { diff --git a/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java b/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java index a81d3a2c894..580eeeb75a7 100644 --- a/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/RefreshPolicyExcelConfigData.java @@ -6,11 +6,12 @@ import java.util.*; import lombok.Getter; +@Getter @ResourceType(name = "RefreshPolicyExcelConfigData.json") public class RefreshPolicyExcelConfigData extends GameResource { - @Getter private int id; - @Getter private RefreshType type; - @Getter private String time; + private int id; + private RefreshType type; + private String time; private static int upperBound(List list, int low, int high, int value) { while (low < high) { @@ -48,9 +49,9 @@ public int getIntervalInSeconds(World world) { upperBound( params, (int) params.get(0), (int) params.get(params.size() - 1), (int) temp); var upper_bound = params.get(upper_bound_idx); - if (params.get(params.size() - 1) == upper_bound) { + if (params.get(params.size() - 1).equals(upper_bound)) { return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; - } else if (params.get(0) == upper_bound) { + } else if (params.get(0).equals(upper_bound)) { return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; } return (params.get(upper_bound_idx - 1) - params.get(0)); @@ -64,15 +65,15 @@ public int getIntervalInSeconds(World world) { upperBound( params, (int) params.get(0), (int) params.get(params.size() - 1), (int) temp); var upper_bound = params.get(upper_bound_idx); - if (params.get(params.size() - 1) == upper_bound) { + if (params.get(params.size() - 1).equals(upper_bound)) { return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; - } else if (params.get(0) == upper_bound) { + } else if (params.get(0).equals(upper_bound)) { return (params.get(params.size() - 1) - params.get(0)) + 60 * 60 * 24 * 7; } return (params.get(upper_bound_idx - 1) - params.get(0)); } case REFRESH_DAYBEGIN_INTERVAL: - if (params.size() == 0) return -1; + if (params.isEmpty()) return -1; return params.get(0) * 60 * 60 * 24; } } catch (Exception e) { diff --git a/src/main/java/emu/grasscutter/data/excels/RewardData.java b/src/main/java/emu/grasscutter/data/excels/RewardData.java index 1b817aec2c8..6a076a49a7f 100644 --- a/src/main/java/emu/grasscutter/data/excels/RewardData.java +++ b/src/main/java/emu/grasscutter/data/excels/RewardData.java @@ -3,21 +3,18 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.common.ItemParamData; import java.util.List; +import lombok.Getter; @ResourceType(name = "RewardExcelConfigData.json") public class RewardData extends GameResource { public int rewardId; - public List rewardItemList; + @Getter public List rewardItemList; @Override public int getId() { return rewardId; } - public List getRewardItemList() { - return rewardItemList; - } - @Override public void onLoad() { rewardItemList = rewardItemList.stream().filter(i -> i.getId() > 0).toList(); diff --git a/src/main/java/emu/grasscutter/data/excels/RewardPreviewData.java b/src/main/java/emu/grasscutter/data/excels/RewardPreviewData.java index dad51e911d3..ced3053b882 100644 --- a/src/main/java/emu/grasscutter/data/excels/RewardPreviewData.java +++ b/src/main/java/emu/grasscutter/data/excels/RewardPreviewData.java @@ -8,7 +8,7 @@ @ResourceType(name = "RewardPreviewExcelConfigData.json", loadPriority = LoadPriority.HIGH) public class RewardPreviewData extends GameResource { - @Getter(onMethod_ = @Override) + @Getter(onMethod = @__(@Override)) private int id; private ItemParamStringData[] previewItems; @@ -25,7 +25,7 @@ public void onLoad() { Arrays.stream(this.previewItems) .filter(d -> d.getId() > 0 && d.getCount() != null && !d.getCount().isEmpty()) .map(ItemParamStringData::toItemParamData) - .toArray(size -> new ItemParamData[size]); + .toArray(ItemParamData[]::new); } else { this.previewItemsArray = new ItemParamData[0]; } diff --git a/src/main/java/emu/grasscutter/data/excels/ShopGoodsData.java b/src/main/java/emu/grasscutter/data/excels/ShopGoodsData.java index 5c1482f4d71..4a95ea2ca15 100644 --- a/src/main/java/emu/grasscutter/data/excels/ShopGoodsData.java +++ b/src/main/java/emu/grasscutter/data/excels/ShopGoodsData.java @@ -5,25 +5,27 @@ import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.game.shop.ShopInfo; import java.util.List; +import lombok.Getter; @ResourceType(name = "ShopGoodsExcelConfigData.json") public class ShopGoodsData extends GameResource { - private int goodsId; - private int shopType; - private int itemId; + @Getter private int goodsId; + @Getter private int shopType; + @Getter private int itemId; - private int itemCount; + @Getter private int itemCount; - private int costScoin; - private int costHcoin; - private int costMcoin; + @Getter private int costScoin; + @Getter private int costHcoin; + @Getter private int costMcoin; - private List costItems; - private int minPlayerLevel; - private int maxPlayerLevel; + @Getter private List costItems; + @Getter private int minPlayerLevel; + @Getter private int maxPlayerLevel; - private int buyLimit; + @Getter private int buyLimit; + @Getter @SerializedName( value = "subTabId", alternate = {"secondarySheetId"}) @@ -32,7 +34,7 @@ public class ShopGoodsData extends GameResource { private String refreshType; private transient ShopInfo.ShopRefreshType refreshTypeEnum; - private int refreshParam; + @Getter private int refreshParam; @Override public void onLoad() { @@ -53,59 +55,7 @@ public int getId() { return getGoodsId(); } - public int getGoodsId() { - return goodsId; - } - - public int getShopType() { - return shopType; - } - - public int getItemId() { - return itemId; - } - - public int getItemCount() { - return itemCount; - } - - public int getCostScoin() { - return costScoin; - } - - public int getCostHcoin() { - return costHcoin; - } - - public int getCostMcoin() { - return costMcoin; - } - - public List getCostItems() { - return costItems; - } - - public int getMinPlayerLevel() { - return minPlayerLevel; - } - - public int getMaxPlayerLevel() { - return maxPlayerLevel; - } - - public int getBuyLimit() { - return buyLimit; - } - - public int getSubTabId() { - return subTabId; - } - public ShopInfo.ShopRefreshType getRefreshType() { return refreshTypeEnum; } - - public int getRefreshParam() { - return refreshParam; - } } diff --git a/src/main/java/emu/grasscutter/data/excels/StatuePromoteData.java b/src/main/java/emu/grasscutter/data/excels/StatuePromoteData.java index fd3afc8eb06..0ddb6c4393b 100644 --- a/src/main/java/emu/grasscutter/data/excels/StatuePromoteData.java +++ b/src/main/java/emu/grasscutter/data/excels/StatuePromoteData.java @@ -4,13 +4,15 @@ import emu.grasscutter.data.common.ItemParamData; import lombok.*; +@Setter +@Getter @ResourceType(name = "StatuePromoteExcelConfigData.json") public class StatuePromoteData extends GameResource { - @Getter @Setter private int level; - @Getter @Setter private int cityId; - @Getter @Setter private ItemParamData[] costItems; - @Getter @Setter private int[] rewardIdList; - @Getter @Setter private int stamina; + private int level; + private int cityId; + private ItemParamData[] costItems; + private int[] rewardIdList; + private int stamina; @Override public int getId() { diff --git a/src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java b/src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java index 3a3b7836d0d..d67cab89fae 100644 --- a/src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java +++ b/src/main/java/emu/grasscutter/data/excels/achievement/AchievementData.java @@ -14,7 +14,7 @@ public class AchievementData extends GameResource { private static final AtomicBoolean isDivided = new AtomicBoolean(); private int goalId; private int preStageAchievementId; - private Set groupAchievementIdList = new HashSet<>(); + private final Set groupAchievementIdList = new HashSet<>(); private boolean isParent; private long titleTextMapHash; private long descTextMapHash; diff --git a/src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java b/src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java index ebb1d3c4f03..afe41f20e15 100644 --- a/src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/activity/ActivityCondExcelConfigData.java @@ -15,9 +15,10 @@ public class ActivityCondExcelConfigData extends GameResource { LogicType condComb; List cond; + @Getter public static class ActivityConfigCondition { - @Getter private ActivityConditions type; - @Getter private List param; + private ActivityConditions type; + private List param; public int[] paramArray() { return param.stream().mapToInt(Integer::intValue).toArray(); diff --git a/src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java b/src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java index 0f8d2ceb2b4..56af01206fa 100644 --- a/src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java +++ b/src/main/java/emu/grasscutter/data/excels/activity/ActivityShopData.java @@ -5,11 +5,12 @@ import java.util.List; import lombok.Getter; +@Getter @ResourceType(name = "ActivityShopOverallExcelConfigData.json") public class ActivityShopData extends GameResource { - @Getter private int scheduleId; - @Getter private ShopType shopType; - @Getter private List sheetList; + private int scheduleId; + private ShopType shopType; + private List sheetList; @Override public int getId() { diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java index 9468a4c5743..dc611d29ce2 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCostumeData.java @@ -2,33 +2,22 @@ import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = "AvatarCostumeExcelConfigData.json") public class AvatarCostumeData extends GameResource { @SerializedName(value = "skinId", alternate = "costumeId") private int skinId; - private int itemId; - private int characterId; - private int quality; + @Getter private int itemId; + @Getter private int characterId; + @Getter private int quality; @Override public int getId() { return this.skinId; } - public int getItemId() { - return this.itemId; - } - - public int getCharacterId() { - return characterId; - } - - public int getQuality() { - return quality; - } - @Override public void onLoad() { GameData.getAvatarCostumeDataItemIdMap().put(this.getItemId(), this); diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java index 6b58a711b3a..9ede549994a 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarCurveData.java @@ -4,10 +4,11 @@ import emu.grasscutter.data.common.CurveInfo; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; @ResourceType(name = "AvatarCurveExcelConfigData.json") public class AvatarCurveData extends GameResource { - private int level; + @Getter private int level; private CurveInfo[] curveInfos; private Map curveInfoMap; @@ -17,10 +18,6 @@ public int getId() { return this.level; } - public int getLevel() { - return level; - } - public Map getCurveInfos() { return curveInfoMap; } diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java index d897fc4e7d3..1b08233280e 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarData.java @@ -55,7 +55,7 @@ public class AvatarData extends GameResource { @Getter private IntList abilities; @Getter - private List abilitieNames = new ArrayList<>(); + private final List abilitieNames = new ArrayList<>(); @Getter private List fetters; diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java index dda483808b7..105e55d295e 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarFlycloakData.java @@ -1,21 +1,18 @@ package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = "AvatarFlycloakExcelConfigData.json") public class AvatarFlycloakData extends GameResource { private int flycloakId; - private long nameTextMapHash; + @Getter private long nameTextMapHash; @Override public int getId() { return this.flycloakId; } - public long getNameTextMapHash() { - return nameTextMapHash; - } - @Override public void onLoad() {} } diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java index 1eae299e372..a26fe6c3af6 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarLevelData.java @@ -1,7 +1,9 @@ package emu.grasscutter.data.excels.avatar; import emu.grasscutter.data.*; +import lombok.Getter; +@Getter @ResourceType(name = "AvatarLevelExcelConfigData.json") public class AvatarLevelData extends GameResource { private int level; @@ -11,12 +13,4 @@ public class AvatarLevelData extends GameResource { public int getId() { return this.level; } - - public int getLevel() { - return level; - } - - public int getExp() { - return exp; - } } diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java index 8972de6e9f0..acf0d826cf4 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarPromoteData.java @@ -3,51 +3,28 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.common.*; import java.util.ArrayList; +import lombok.Getter; @ResourceType(name = "AvatarPromoteExcelConfigData.json") public class AvatarPromoteData extends GameResource { - private int avatarPromoteId; - private int promoteLevel; + @Getter private int avatarPromoteId; + @Getter private int promoteLevel; private int scoinCost; - private ItemParamData[] costItems; - private int unlockMaxLevel; - private FightPropData[] addProps; - private int requiredPlayerLevel; + @Getter private ItemParamData[] costItems; + @Getter private int unlockMaxLevel; + @Getter private FightPropData[] addProps; + @Getter private int requiredPlayerLevel; @Override public int getId() { return (avatarPromoteId << 8) + promoteLevel; } - public int getAvatarPromoteId() { - return avatarPromoteId; - } - - public int getPromoteLevel() { - return promoteLevel; - } - - public ItemParamData[] getCostItems() { - return costItems; - } - public int getCoinCost() { return scoinCost; } - public FightPropData[] getAddProps() { - return addProps; - } - - public int getUnlockMaxLevel() { - return unlockMaxLevel; - } - - public int getRequiredPlayerLevel() { - return requiredPlayerLevel; - } - @Override public void onLoad() { // Trim item params diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java index 0f844701da8..474dca103bd 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java @@ -52,7 +52,7 @@ public void onLoad() { this.elementType = ElementType.None; } // Set embryo abilities (if player skill depot) - if (getSkillDepotAbilityGroup() != null && getSkillDepotAbilityGroup().length() > 0) { + if (getSkillDepotAbilityGroup() != null && !getSkillDepotAbilityGroup().isEmpty()) { AvatarConfig config = GameDepot.getPlayerAbilities().get(getSkillDepotAbilityGroup()); if (config != null) { @@ -67,7 +67,7 @@ public void onLoad() { Optional.ofNullable(this.talents) .map(talents -> talents.get(0)) .map(i -> GameData.getAvatarTalentDataMap().get((int) i)) - .map(talentData -> talentData.getMainCostItemId()) + .map(AvatarTalentData::getMainCostItemId) .ifPresent(itemId -> this.talentCostItemId = itemId); } diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java index be08ede9f34..d317edf433d 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarTalentData.java @@ -4,18 +4,19 @@ import emu.grasscutter.data.ResourceType.LoadPriority; import emu.grasscutter.data.common.FightPropData; import java.util.ArrayList; +import lombok.Getter; @ResourceType(name = "AvatarTalentExcelConfigData.json", loadPriority = LoadPriority.HIGHEST) public class AvatarTalentData extends GameResource { private int talentId; private int prevTalent; - private long nameTextMapHash; - private String icon; - private int mainCostItemId; - private int mainCostItemCount; - private String openConfig; - private FightPropData[] addProps; - private float[] paramList; + @Getter private long nameTextMapHash; + @Getter private String icon; + @Getter private int mainCostItemId; + @Getter private int mainCostItemCount; + @Getter private String openConfig; + @Getter private FightPropData[] addProps; + @Getter private float[] paramList; @Override public int getId() { @@ -26,37 +27,9 @@ public int PrevTalent() { return prevTalent; } - public long getNameTextMapHash() { - return nameTextMapHash; - } - - public String getIcon() { - return icon; - } - - public int getMainCostItemId() { - return mainCostItemId; - } - - public int getMainCostItemCount() { - return mainCostItemCount; - } - - public String getOpenConfig() { - return openConfig; - } - - public FightPropData[] getAddProps() { - return addProps; - } - - public float[] getParamList() { - return paramList; - } - @Override public void onLoad() { - ArrayList parsed = new ArrayList(getAddProps().length); + ArrayList parsed = new ArrayList<>(getAddProps().length); for (FightPropData prop : getAddProps()) { if (prop.getPropType() != null || prop.getValue() == 0f) { prop.onLoad(); diff --git a/src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java index ee14db8e2d0..fa28411dcd0 100644 --- a/src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexMaterialData.java @@ -1,25 +1,15 @@ package emu.grasscutter.data.excels.codex; import emu.grasscutter.data.*; +import lombok.Getter; +@Getter @ResourceType(name = {"MaterialCodexExcelConfigData.json"}) public class CodexMaterialData extends GameResource { private int Id; private int materialId; private int sortOrder; - public int getSortOrder() { - return sortOrder; - } - - public int getMaterialId() { - return materialId; - } - - public int getId() { - return Id; - } - @Override public void onLoad() { GameData.getCodexMaterialDataIdMap().put(this.getMaterialId(), this); diff --git a/src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java index 1b373bfbe65..4969e350ab5 100644 --- a/src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexQuestData.java @@ -1,31 +1,16 @@ package emu.grasscutter.data.excels.codex; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = {"QuestCodexExcelConfigData.json"}) public class CodexQuestData extends GameResource { - private int Id; - private int parentQuestId; - private int chapterId; - private int sortOrder; + @Getter private int Id; + @Getter private int parentQuestId; + @Getter private int chapterId; + @Getter private int sortOrder; private boolean isDisuse; - public int getParentQuestId() { - return parentQuestId; - } - - public int getId() { - return Id; - } - - public int getChapterId() { - return chapterId; - } - - public int getSortOrder() { - return sortOrder; - } - public boolean getIsDisuse() { return isDisuse; } diff --git a/src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java b/src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java index 7d585839e37..30e7e4a62d5 100644 --- a/src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java +++ b/src/main/java/emu/grasscutter/data/excels/codex/CodexWeaponData.java @@ -1,30 +1,19 @@ package emu.grasscutter.data.excels.codex; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = {"WeaponCodexExcelConfigData.json"}) public class CodexWeaponData extends GameResource { - private int Id; - private int weaponId; + @Getter private int Id; + @Getter private int weaponId; private int gadgetId; - private int sortOrder; - - public int getSortOrder() { - return sortOrder; - } - - public int getWeaponId() { - return weaponId; - } + @Getter private int sortOrder; public int getGadgetId() { return weaponId; } - public int getId() { - return Id; - } - @Override public void onLoad() { GameData.getCodexWeaponDataIdMap().put(this.getWeaponId(), this); diff --git a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java index 12f81f30394..cdd5aab139b 100644 --- a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonChallengeConfigData.java @@ -9,7 +9,7 @@ @Getter @ResourceType(name = "DungeonChallengeConfigData.json") public class DungeonChallengeConfigData extends GameResource { - private int id; + @Getter private int id; private ChallengeType challengeType; private boolean noSuccessHint; private boolean noFailHint; @@ -42,10 +42,6 @@ public class DungeonChallengeConfigData extends GameResource { alternate = {"NJBJIKAIENN"}) private AllowAnimationType animationOnSubFail; - public int getId() { - return id; - } - public enum InterruptButtonType { INTERRUPT_BUTTON_TYPE_NONE, INTERRUPT_BUTTON_TYPE_HOST, diff --git a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java index 4c92c341b63..6d1c3d7f9bc 100644 --- a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonPassConfigData.java @@ -6,15 +6,17 @@ import java.util.List; import lombok.*; +@Getter @ResourceType(name = "DungeonPassExcelConfigData.json") public class DungeonPassConfigData extends GameResource { - @Getter private int id; - @Getter private LogicType logicType; - @Getter @Setter private List conds; + private int id; + private LogicType logicType; + @Setter private List conds; + @Getter public static class DungeonPassCondition { - @Getter private DungeonPassConditionType condType; - @Getter int[] param; + private DungeonPassConditionType condType; + int[] param; } @Override diff --git a/src/main/java/emu/grasscutter/data/excels/quest/QuestData.java b/src/main/java/emu/grasscutter/data/excels/quest/QuestData.java index a0463f6d1a0..92856756d22 100644 --- a/src/main/java/emu/grasscutter/data/excels/quest/QuestData.java +++ b/src/main/java/emu/grasscutter/data/excels/quest/QuestData.java @@ -11,32 +11,32 @@ import lombok.*; import lombok.experimental.FieldDefaults; -@ResourceType(name = "QuestExcelConfigData.json") @Getter +@ResourceType(name = "QuestExcelConfigData.json") @ToString public class QuestData extends GameResource { - @Getter private int subId; - @Getter private int mainId; - @Getter private int order; - @Getter private long descTextMapHash; - - @Getter private boolean finishParent; - @Getter private boolean isRewind; - - @Getter private LogicType acceptCondComb; - @Getter private LogicType finishCondComb; - @Getter private LogicType failCondComb; - - @Getter private List acceptCond; - @Getter private List finishCond; - @Getter private List failCond; - @Getter private List beginExec; - @Getter private List finishExec; - @Getter private List failExec; - @Getter private Guide guide; - - @Getter private List trialAvatarList; - @Getter private List gainItems; + private int subId; + private int mainId; + private int order; + private long descTextMapHash; + + private boolean finishParent; + private boolean isRewind; + + private LogicType acceptCondComb; + private LogicType finishCondComb; + private LogicType failCondComb; + + private List acceptCond; + private List finishCond; + private List failCond; + private List beginExec; + private List finishExec; + private List failExec; + private Guide guide; + + private List trialAvatarList; + private List gainItems; public static String questConditionKey( @Nonnull Enum type, int firstParam, @Nullable String paramsStr) { diff --git a/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java index 5806db11b8f..3a3c8324513 100644 --- a/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java +++ b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquaryMainPropData.java @@ -8,7 +8,7 @@ @ResourceType(name = "ReliquaryMainPropExcelConfigData.json") @Getter public class ReliquaryMainPropData extends GameResource { - @Getter(onMethod_ = @Override) + @Getter(onMethod = @__(@Override)) private int id; private int propDepotId; diff --git a/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java index 022d2997e14..05eb34e1edb 100644 --- a/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java +++ b/src/main/java/emu/grasscutter/data/excels/reliquary/ReliquarySetData.java @@ -2,12 +2,14 @@ import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = "ReliquarySetExcelConfigData.json") public class ReliquarySetData extends GameResource { private int setId; - private int[] setNeedNum; + @Getter private int[] setNeedNum; + @Getter @SerializedName( value = "equipAffixId", alternate = {"EquipAffixId"}) @@ -18,14 +20,6 @@ public int getId() { return setId; } - public int[] getSetNeedNum() { - return setNeedNum; - } - - public int getEquipAffixId() { - return equipAffixId; - } - @Override public void onLoad() {} } diff --git a/src/main/java/emu/grasscutter/data/excels/scene/SceneData.java b/src/main/java/emu/grasscutter/data/excels/scene/SceneData.java index 07c6e25c224..cd86008a2c6 100644 --- a/src/main/java/emu/grasscutter/data/excels/scene/SceneData.java +++ b/src/main/java/emu/grasscutter/data/excels/scene/SceneData.java @@ -9,7 +9,7 @@ @ResourceType(name = "SceneExcelConfigData.json") @Getter public final class SceneData extends GameResource { - @Getter(onMethod_ = @Override) + @Getter(onMethod = @__(@Override)) private int id; @SerializedName("type") diff --git a/src/main/java/emu/grasscutter/data/excels/scene/SceneTagData.java b/src/main/java/emu/grasscutter/data/excels/scene/SceneTagData.java index d894c5d6541..f1819fa8a3b 100644 --- a/src/main/java/emu/grasscutter/data/excels/scene/SceneTagData.java +++ b/src/main/java/emu/grasscutter/data/excels/scene/SceneTagData.java @@ -8,7 +8,7 @@ @ResourceType(name = "SceneTagConfigData.json") @Getter public final class SceneTagData extends GameResource { - @Getter(onMethod_ = @Override) + @Getter(onMethod = @__(@Override)) private int id; @SerializedName("DJCOAOBDIHP") diff --git a/src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java b/src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java index e9fd62ff6e8..de36bd3b1b7 100644 --- a/src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/tower/TowerLevelData.java @@ -30,8 +30,8 @@ public enum TowerCondType { // Just packaging condition parameters for convenience. @Getter public class TowerCondTimeParams { - private int param1; - private int minimumTimeInSeconds; + private final int param1; + private final int minimumTimeInSeconds; public TowerCondTimeParams(int param1, int minimumTimeInSeconds) { this.param1 = param1; @@ -41,9 +41,9 @@ public TowerCondTimeParams(int param1, int minimumTimeInSeconds) { @Getter public class TowerCondHpParams { - private int sceneId; - private int configId; - private int minimumHpPercentage; + private final int sceneId; + private final int configId; + private final int minimumHpPercentage; public TowerCondHpParams(int sceneId, int configId, int minimumHpPercentage) { this.sceneId = sceneId; diff --git a/src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java b/src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java index 4a050829fe9..77712523df4 100644 --- a/src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java +++ b/src/main/java/emu/grasscutter/data/excels/tower/TowerScheduleData.java @@ -2,7 +2,9 @@ import emu.grasscutter.data.*; import java.util.List; +import lombok.Getter; +@Getter @ResourceType(name = "TowerScheduleExcelConfigData.json") public class TowerScheduleData extends GameResource { private int scheduleId; @@ -19,30 +21,11 @@ public int getId() { public void onLoad() { super.onLoad(); this.schedules = - this.schedules.stream().filter(item -> item.getFloorList().size() > 0).toList(); - } - - public int getScheduleId() { - return scheduleId; - } - - public List getEntranceFloorId() { - return entranceFloorId; - } - - public List getSchedules() { - return schedules; - } - - public int getMonthlyLevelConfigId() { - return monthlyLevelConfigId; + this.schedules.stream().filter(item -> !item.getFloorList().isEmpty()).toList(); } + @Getter public static class ScheduleDetail { private List floorList; - - public List getFloorList() { - return floorList; - } } } diff --git a/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java index 6a532b91fb8..6d5858cefb1 100644 --- a/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java +++ b/src/main/java/emu/grasscutter/data/excels/trial/TrialAvatarActivityDataData.java @@ -10,7 +10,7 @@ @Data @FieldDefaults(level = AccessLevel.PRIVATE) public class TrialAvatarActivityDataData extends GameResource { - @Getter(onMethod_ = @Override) + @Getter(onMethod = @__({@Override})) private int id; private int trialAvatarIndexId; diff --git a/src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java index a35b9b9c2e4..a89b36287eb 100644 --- a/src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponLevelData.java @@ -1,7 +1,9 @@ package emu.grasscutter.data.excels.weapon; import emu.grasscutter.data.*; +import lombok.Getter; +@Getter @ResourceType(name = "WeaponLevelExcelConfigData.json") public class WeaponLevelData extends GameResource { private int level; @@ -11,12 +13,4 @@ public class WeaponLevelData extends GameResource { public int getId() { return this.level; } - - public int getLevel() { - return level; - } - - public int[] getRequiredExps() { - return requiredExps; - } } diff --git a/src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java index 775737e1123..84751156a5b 100644 --- a/src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java +++ b/src/main/java/emu/grasscutter/data/excels/weapon/WeaponPromoteData.java @@ -3,7 +3,9 @@ import emu.grasscutter.data.*; import emu.grasscutter.data.common.*; import java.util.ArrayList; +import lombok.Getter; +@Getter @ResourceType(name = "WeaponPromoteExcelConfigData.json") public class WeaponPromoteData extends GameResource { @@ -20,34 +22,6 @@ public int getId() { return (weaponPromoteId << 8) + promoteLevel; } - public int getWeaponPromoteId() { - return weaponPromoteId; - } - - public int getPromoteLevel() { - return promoteLevel; - } - - public ItemParamData[] getCostItems() { - return costItems; - } - - public int getCoinCost() { - return coinCost; - } - - public FightPropData[] getAddProps() { - return addProps; - } - - public int getUnlockMaxLevel() { - return unlockMaxLevel; - } - - public int getRequiredPlayerLevel() { - return requiredPlayerLevel; - } - @Override public void onLoad() { // Trim item params diff --git a/src/main/java/emu/grasscutter/data/excels/world/WeatherData.java b/src/main/java/emu/grasscutter/data/excels/world/WeatherData.java index 631134257e2..9db8809e4bf 100644 --- a/src/main/java/emu/grasscutter/data/excels/world/WeatherData.java +++ b/src/main/java/emu/grasscutter/data/excels/world/WeatherData.java @@ -4,19 +4,20 @@ import emu.grasscutter.game.props.ClimateType; import lombok.Getter; +@Getter @ResourceType(name = "WeatherExcelConfigData.json") public class WeatherData extends GameResource { - @Getter private int areaID; - @Getter private int weatherAreaId; - @Getter private String maxHeightStr; - @Getter private int gadgetID; - @Getter private boolean isDefaultValid; - @Getter private String templateName; - @Getter private int priority; - @Getter private String profileName; - @Getter private ClimateType defaultClimate; - @Getter private boolean isUseDefault; - @Getter private int sceneID; + private int areaID; + private int weatherAreaId; + private String maxHeightStr; + private int gadgetID; + private boolean isDefaultValid; + private String templateName; + private int priority; + private String profileName; + private ClimateType defaultClimate; + private boolean isUseDefault; + private int sceneID; @Override public int getId() { diff --git a/src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java b/src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java index 0967c987153..0ffc0155683 100644 --- a/src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java +++ b/src/main/java/emu/grasscutter/data/excels/world/WorldLevelData.java @@ -1,21 +1,18 @@ package emu.grasscutter.data.excels.world; import emu.grasscutter.data.*; +import lombok.Getter; @ResourceType(name = "WorldLevelExcelConfigData.json") public class WorldLevelData extends GameResource { private int level; - private int monsterLevel; + @Getter private int monsterLevel; @Override public int getId() { return this.level; } - public int getMonsterLevel() { - return monsterLevel; - } - @Override public void onLoad() {} } diff --git a/src/main/java/emu/grasscutter/data/server/Grid.java b/src/main/java/emu/grasscutter/data/server/Grid.java index 624556d481a..126e247689f 100644 --- a/src/main/java/emu/grasscutter/data/server/Grid.java +++ b/src/main/java/emu/grasscutter/data/server/Grid.java @@ -6,12 +6,18 @@ import emu.grasscutter.game.world.*; import emu.grasscutter.scripts.SceneIndexManager; import java.util.*; +import lombok.Getter; public class Grid { public transient RTree>, Geometry> gridOptimized = null; - private transient Set nearbyGroups = new HashSet<>(100); + private final transient Set nearbyGroups = new HashSet<>(100); - public Map> grid = new LinkedHashMap<>(); + /** + * -- GETTER -- + * + * @return The correctly loaded grid map. + */ + @Getter public Map> grid = new LinkedHashMap<>(); /** Creates an optimized cache of the grid. */ private void optimize() { @@ -23,13 +29,6 @@ private void optimize() { } } - /** - * @return The correctly loaded grid map. - */ - public Map> getGrid() { - return this.grid; - } - public Set getNearbyGroups(int vision_level, Position position) { this.optimize(); // Check to see if the grid is optimized. diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index fffc6ab738d..4847a19cb17 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -550,7 +550,7 @@ public static void saveMusicGameBeatmap(MusicGameBeatmap musicGameBeatmap) { .first(); } catch (IllegalArgumentException e) { Grasscutter.getLogger() - .debug("Error occurred while getting uid " + uid + "'s achievement data", e); + .debug("Error occurred while getting uid {}'s achievement data", uid, e); DatabaseManager.getGameDatabase().getCollection("achievements").deleteMany(eq("uid", uid)); return null; } diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 7331bccb725..0330d64a33c 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -11,15 +11,12 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerRunMode; import emu.grasscutter.game.Account; +import lombok.Getter; public final class DatabaseManager { - private static Datastore gameDatastore; + @Getter private static Datastore gameDatastore; private static Datastore dispatchDatastore; - public static Datastore getGameDatastore() { - return gameDatastore; - } - public static Datastore getAccountDatastore() { if (Grasscutter.getRunMode() == ServerRunMode.HYBRID) return gameDatastore; else return dispatchDatastore; diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index c796b998183..4c66ebedf41 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -7,29 +7,35 @@ import emu.grasscutter.utils.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +import lombok.Setter; import org.bson.Document; @Entity(value = "accounts", useDiscriminator = false) public class Account { - @Id private String id; + @Setter @Getter @Id private String id; + @Setter + @Getter @Indexed(options = @IndexOptions(unique = true)) @Collation(locale = "simple", caseLevel = true) private String username; - private String password; // Unused for now + @Setter @Getter private String password; // Unused for now private int reservedPlayerId; - private String email; + @Setter private String email; - private String token; - private String sessionKey; // Session token for dispatch server - private List permissions; - private Locale locale; + @Setter @Getter private String token; + @Getter private String sessionKey; // Session token for dispatch server + /** -- GETTER -- The collection of a player's permissions. */ + @Getter private final List permissions; - private String banReason; - private int banEndTime; - private int banStartTime; + @Setter @Getter private Locale locale; + + @Setter @Getter private String banReason; + @Setter @Getter private int banEndTime; + @Setter @Getter private int banStartTime; private boolean isBanned; @Deprecated @@ -64,38 +70,6 @@ public static boolean permissionMatchesWildcard(String wildcard, String[] permis return (wildcardParts.length == permissionParts.length); } - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - public int getReservedPlayerUid() { return this.reservedPlayerId; } @@ -113,52 +87,12 @@ public String getEmail() { } } - public void setEmail(String email) { - this.email = email; - } - - public String getSessionKey() { - return this.sessionKey; - } - public String generateSessionKey() { this.sessionKey = Utils.bytesToHex(Crypto.createSessionKey(32)); this.save(); return this.sessionKey; } - public Locale getLocale() { - return locale; - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public String getBanReason() { - return banReason; - } - - public void setBanReason(String banReason) { - this.banReason = banReason; - } - - public int getBanEndTime() { - return banEndTime; - } - - public void setBanEndTime(int banEndTime) { - this.banEndTime = banEndTime; - } - - public int getBanStartTime() { - return banStartTime; - } - - public void setBanStartTime(int banStartTime) { - this.banStartTime = banStartTime; - } - public boolean isBanned() { if (banEndTime > 0 && banEndTime < System.currentTimeMillis() / 1000) { this.isBanned = false; @@ -175,11 +109,6 @@ public void setBanned(boolean isBanned) { this.isBanned = isBanned; } - /** The collection of a player's permissions. */ - public List getPermissions() { - return this.permissions; - } - public boolean addPermission(String permission) { if (this.permissions.contains(permission)) return false; this.permissions.add(permission); diff --git a/src/main/java/emu/grasscutter/game/CoopRequest.java b/src/main/java/emu/grasscutter/game/CoopRequest.java index f1caf0f8b0f..ca4c0c6aaa0 100644 --- a/src/main/java/emu/grasscutter/game/CoopRequest.java +++ b/src/main/java/emu/grasscutter/game/CoopRequest.java @@ -1,7 +1,9 @@ package emu.grasscutter.game; import emu.grasscutter.game.player.Player; +import lombok.Getter; +@Getter public class CoopRequest { private final Player requester; private final long requestTime; @@ -13,18 +15,6 @@ public CoopRequest(Player requester) { this.expireTime = this.requestTime + 10000; } - public Player getRequester() { - return requester; - } - - public long getRequestTime() { - return requestTime; - } - - public long getExpireTime() { - return expireTime; - } - public boolean isExpired() { return System.currentTimeMillis() > getExpireTime(); } diff --git a/src/main/java/emu/grasscutter/game/ability/Ability.java b/src/main/java/emu/grasscutter/game/ability/Ability.java index 0c7f5337eb0..92ee5c08064 100644 --- a/src/main/java/emu/grasscutter/game/ability/Ability.java +++ b/src/main/java/emu/grasscutter/game/ability/Ability.java @@ -12,20 +12,21 @@ import lombok.Getter; public class Ability { - @Getter private AbilityData data; - @Getter private GameEntity owner; - @Getter private Player playerOwner; + @Getter private final AbilityData data; + @Getter private final GameEntity owner; + @Getter private final Player playerOwner; - @Getter private AbilityManager manager; + @Getter private final AbilityManager manager; - @Getter private Map modifiers = new HashMap<>(); - @Getter private Object2FloatMap abilitySpecials = new Object2FloatOpenHashMap<>(); + @Getter private final Map modifiers = new HashMap<>(); + @Getter private final Object2FloatMap abilitySpecials = new Object2FloatOpenHashMap<>(); @Getter - private static Map> abilitySpecialsModified = new HashMap<>(); + private static final Map> abilitySpecialsModified = + new HashMap<>(); - @Getter private int hash; - @Getter private Set avatarSkillStartIds; + @Getter private final int hash; + @Getter private final Set avatarSkillStartIds; public Ability(AbilityData data, GameEntity owner, Player playerOwner) { this.data = data; diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java index b5bef427651..c23dc5fc130 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java @@ -83,14 +83,13 @@ private void onPossibleElementalBurst(Ability ability, AbilityModifier modifier, boolean skillInvincibility = modifier.state == AbilityModifier.State.Invincible; if (modifier.onAdded != null) { skillInvincibility |= - Arrays.stream(modifier.onAdded) - .filter( - action -> - action.type == AbilityModifierAction.Type.AttachAbilityStateResistance - && action.resistanceListID == 11002) - .toList() - .size() - > 0; + !Arrays.stream(modifier.onAdded) + .filter( + action -> + action.type == AbilityModifierAction.Type.AttachAbilityStateResistance + && action.resistanceListID == 11002) + .toList() + .isEmpty(); } if (this.burstCasterId == entityId @@ -180,14 +179,11 @@ public void executeMixin(Ability ability, AbilityMixinData mixinData, ByteString public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception { Grasscutter.getLogger() .trace( - "Ability invoke: " - + invoke - + " " - + invoke.getArgumentType() - + " (" - + invoke.getArgumentTypeValue() - + "): " - + this.player.getScene().getEntityById(invoke.getEntityId())); + "Ability invoke: {} {} ({}): {}", + invoke, + invoke.getArgumentType(), + invoke.getArgumentTypeValue(), + this.player.getScene().getEntityById(invoke.getEntityId())); var entity = this.player.getScene().getEntityById(invoke.getEntityId()); if (entity != null) { Grasscutter.getLogger() @@ -214,7 +210,8 @@ public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception { if (invoke.getHead().getTargetId() != 0) { Grasscutter.getLogger() - .trace("Target: " + this.player.getScene().getEntityById(invoke.getHead().getTargetId())); + .trace( + "Target: {}", this.player.getScene().getEntityById(invoke.getHead().getTargetId())); } if (invoke.getHead().getLocalId() != 0) { this.handleServerInvoke(invoke); diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java b/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java index 370412fe5bb..d5f8d760f71 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityModifierController.java @@ -3,11 +3,12 @@ import emu.grasscutter.data.binout.*; import lombok.Getter; +@Getter public class AbilityModifierController { - @Getter private Ability ability; + private final Ability ability; - @Getter private AbilityData abilityData; - @Getter private AbilityModifier modifierData; + private final AbilityData abilityData; + private final AbilityModifier modifierData; public AbilityModifierController( Ability ability, AbilityData abilityData, AbilityModifier modifierData) { diff --git a/src/main/java/emu/grasscutter/game/achievement/Achievement.java b/src/main/java/emu/grasscutter/game/achievement/Achievement.java index 6f3a7dae1ac..2e935e1113e 100644 --- a/src/main/java/emu/grasscutter/game/achievement/Achievement.java +++ b/src/main/java/emu/grasscutter/game/achievement/Achievement.java @@ -9,8 +9,8 @@ @Getter public class Achievement { @Setter private Status status; - private int id; - private int totalProgress; + private final int id; + private final int totalProgress; @Setter private int curProgress; @Setter private int finishTimestampSec; diff --git a/src/main/java/emu/grasscutter/game/achievement/AchievementControlReturns.java b/src/main/java/emu/grasscutter/game/achievement/AchievementControlReturns.java index c177f803574..942eb52caa8 100644 --- a/src/main/java/emu/grasscutter/game/achievement/AchievementControlReturns.java +++ b/src/main/java/emu/grasscutter/game/achievement/AchievementControlReturns.java @@ -32,13 +32,14 @@ public static AchievementControlReturns notYetAchieved() { return new AchievementControlReturns(Return.NOT_YET_ACHIEVED); } + @Getter public enum Return { SUCCESS("commands.achievement.success."), ACHIEVEMENT_NOT_FOUND("commands.achievement.fail.achievement_not_found"), ALREADY_ACHIEVED("commands.achievement.fail.already_achieved"), NOT_YET_ACHIEVED("commands.achievement.fail.not_yet_achieved"); - @Getter private final String key; + private final String key; Return(String key) { this.key = key; diff --git a/src/main/java/emu/grasscutter/game/achievement/Achievements.java b/src/main/java/emu/grasscutter/game/achievement/Achievements.java index 929c382cb93..acc55006e5d 100644 --- a/src/main/java/emu/grasscutter/game/achievement/Achievements.java +++ b/src/main/java/emu/grasscutter/game/achievement/Achievements.java @@ -61,11 +61,10 @@ private static Map init() { GameData.getAchievementDataMap().values().stream() .filter(AchievementData::isUsed) .forEach( - a -> { - map.put( - a.getId(), - new Achievement(Status.STATUS_UNFINISHED, a.getId(), a.getProgress(), 0, 0)); - }); + a -> + map.put( + a.getId(), + new Achievement(Status.STATUS_UNFINISHED, a.getId(), a.getProgress(), 0, 0))); return map; } @@ -177,14 +176,13 @@ private void sendUpdatePacket(List achievement) { return this.getAchievementList() .computeIfAbsent( achievementId, - id -> { - return new Achievement( - Status.STATUS_UNFINISHED, - id, - GameData.getAchievementDataMap().get(id.intValue()).getProgress(), - 0, - 0); - }); + id -> + new Achievement( + Status.STATUS_UNFINISHED, + id, + GameData.getAchievementDataMap().get(id.intValue()).getProgress(), + 0, + 0)); } public boolean isInvalid(int achievementId) { @@ -235,6 +233,10 @@ public void takeReward(List ids) { }); var a = this.getAchievement(i); + if (a == null) { + Grasscutter.getLogger().warn("null returned while getting achievement!"); + return; + } a.setStatus(Status.STATUS_REWARD_TAKEN); this.save(); this.sendUpdatePacket(a); diff --git a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java index abf45b02da3..2bc47d43f73 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java @@ -13,7 +13,7 @@ public abstract class ActivityConditionBaseHandler { * Execute activity condition handler and return result of it's calculation * * @param activityData {@link PlayerActivityData} object containing info about activity - * @param activityConfig + * @param activityConfig {@link ActivityConfigItem} object containing info about activity * @param params params for handler * @return result of condition calculation */ diff --git a/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java b/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java index ea7a4b30ed0..222971c3b16 100644 --- a/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java +++ b/src/main/java/emu/grasscutter/game/activity/condition/AllActivityConditionBuilder.java @@ -26,6 +26,7 @@ private Map initActivityCondit Reflections reflector = Grasscutter.reflector; return reflector.getTypesAnnotatedWith(ActivityCondition.class).stream() .map(this::newInstance) + .filter(Objects::nonNull) .map(h -> new AbstractMap.SimpleEntry<>(extractActionType(h), h)) .collect( Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); diff --git a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java index 1778f43282e..b9e7e8c43d0 100644 --- a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java +++ b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java @@ -18,7 +18,7 @@ protected boolean isMeet(String... param) { if (paramList.isEmpty()) return false; val paramCond = Stream.of(paramList.get(0).split(",")).toList(); - return Stream.of(param).allMatch(x -> paramCond.contains(x)); + return Stream.of(param).allMatch(paramCond::contains); } @Override diff --git a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java index 71960772142..76f358a0585 100644 --- a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java +++ b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityHandler.java @@ -16,9 +16,11 @@ import java.util.stream.Stream; import lombok.*; +@Setter +@Getter @GameActivity(ActivityType.NEW_ACTIVITY_TRIAL_AVATAR) public class TrialAvatarActivityHandler extends ActivityHandler { - @Getter @Setter private int selectedTrialAvatarIndex; + private int selectedTrialAvatarIndex; @Override public void onInitPlayerActivityData(PlayerActivityData playerActivityData) { diff --git a/src/main/java/emu/grasscutter/game/avatar/Avatar.java b/src/main/java/emu/grasscutter/game/avatar/Avatar.java index be5774ed06d..932930b5984 100644 --- a/src/main/java/emu/grasscutter/game/avatar/Avatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/Avatar.java @@ -8,18 +8,32 @@ 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.avatar.*; +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; import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData.InherentProudSkillOpens; -import emu.grasscutter.data.excels.reliquary.*; +import emu.grasscutter.data.excels.avatar.AvatarTalentData; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryLevelData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; +import emu.grasscutter.data.excels.reliquary.ReliquarySetData; import emu.grasscutter.data.excels.trial.TrialAvatarTemplateData; -import emu.grasscutter.data.excels.weapon.*; +import emu.grasscutter.data.excels.weapon.WeaponCurveData; +import emu.grasscutter.data.excels.weapon.WeaponPromoteData; import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.entity.*; -import emu.grasscutter.game.inventory.*; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.entity.EntityWeapon; +import emu.grasscutter.game.inventory.EquipType; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.*; +import emu.grasscutter.game.props.ElementType; +import emu.grasscutter.game.props.FetterState; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; import emu.grasscutter.net.proto.AvatarInfoOuterClass.AvatarInfo; import emu.grasscutter.net.proto.AvatarSkillInfoOuterClass.AvatarSkillInfo; @@ -34,8 +48,12 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; -import javax.annotation.*; -import lombok.*; +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; @Entity(value = "avatars", useDiscriminator = false) @@ -61,13 +79,13 @@ public class Avatar { private List fetters; - private Map skillLevelMap = new Int2IntArrayMap(7); // Talent levels + private final Map skillLevelMap = new Int2IntArrayMap(7); // Talent levels @Transient @Getter - private Map skillExtraChargeMap = new Int2IntArrayMap(2); // Charges + private final Map skillExtraChargeMap = new Int2IntArrayMap(2); // Charges @Transient - private Map proudSkillBonusMap = + private final Map proudSkillBonusMap = new Int2IntArrayMap(2); // Talent bonus levels (from const) @Getter private int skillDepotId; @@ -380,6 +398,7 @@ public float getFightProperty(FightProperty prop) { public Map getSkillLevelMap() { // Returns a copy of the skill levels for the current skillDepot. var map = new Int2IntOpenHashMap(); + if (this.skillDepot == null) return map; this.skillDepot .getSkillsAndEnergySkill() .forEach( @@ -391,6 +410,7 @@ public float getFightProperty(FightProperty prop) { // levels. public Map getProudSkillBonusMap() { var map = new Int2IntArrayMap(); + if (this.skillDepot == null) return map; this.skillDepot .getSkillsAndEnergySkill() .forEach( @@ -636,7 +656,7 @@ public void recalcStats(boolean forceSendAbilityChange) { } } // Add weapon skill from affixes - if (weapon.getAffixes() != null && weapon.getAffixes().size() > 0) { + if (weapon.getAffixes() != null && !weapon.getAffixes().isEmpty()) { // Weapons usually dont have more than one affix but just in case... for (int af : weapon.getAffixes()) { if (af == 0) { @@ -740,7 +760,7 @@ public void addToExtraAbilityEmbryos(String openConfig) { } public void addToExtraAbilityEmbryos(String openConfig, boolean forceAdd) { - if (openConfig == null || openConfig.length() == 0) { + if (openConfig == null || openConfig.isEmpty()) { return; } @@ -776,12 +796,13 @@ public void calcConstellation(OpenConfigEntry entry, boolean notifyClient) { Stream.of(entry.getSkillPointModifiers()) .mapToInt(SkillPointModifier::getSkillId) .forEach( - skillId -> { - this.getPlayer() - .sendPacket( - new PacketAvatarSkillMaxChargeCountNotify( - this, skillId, this.getSkillExtraChargeMap().getOrDefault(skillId, 0))); - }); + skillId -> + this.getPlayer() + .sendPacket( + new PacketAvatarSkillMaxChargeCountNotify( + this, + skillId, + this.getSkillExtraChargeMap().getOrDefault(skillId, 0)))); } } @@ -801,7 +822,7 @@ public void recalcConstellations() { .filter(Objects::nonNull) .map(AvatarTalentData::getOpenConfig) .filter(Objects::nonNull) - .filter(openConfig -> openConfig.length() > 0) + .filter(openConfig -> !openConfig.isEmpty()) .map(GameData.getOpenConfigEntries()::get) .filter(Objects::nonNull) .forEach(e -> this.calcConstellation(e, false)); @@ -824,13 +845,14 @@ private boolean calcConstellationExtraCharges(OpenConfigEntry entry) { } private boolean calcConstellationExtraLevels(OpenConfigEntry entry) { + if (this.skillDepot == null) return false; int skillId = switch (entry.getExtraTalentIndex()) { case 9 -> this.skillDepot.getEnergySkill(); // Ult skill case 2 -> (this.skillDepot.getSkills().size() >= 2) ? this.skillDepot.getSkills().get(1) : 0; // E skill - case 1 -> (this.skillDepot.getSkills().size() >= 1) + case 1 -> (!this.skillDepot.getSkills().isEmpty()) ? this.skillDepot.getSkills().get(0) : 0; // Normal Attack (Liney) default -> 0; @@ -906,7 +928,7 @@ public boolean unlockConstellation() { public boolean unlockConstellation(boolean skipPayment) { int currentTalentLevel = this.getCoreProudSkillLevel(); - if (currentTalentLevel < 0) return false; + if (currentTalentLevel < 0 || this.skillDepot == null) return false; int talentId = this.skillDepot.getTalents().get(currentTalentLevel); return this.unlockConstellation(talentId, skipPayment); } diff --git a/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java b/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java index 1d2002e7bef..c75ebaec4ad 100644 --- a/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java +++ b/src/main/java/emu/grasscutter/game/avatar/AvatarStorage.java @@ -17,9 +17,10 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import java.util.Iterator; import java.util.List; +import lombok.Getter; public class AvatarStorage extends BasePlayerManager implements Iterable { - private final Int2ObjectMap avatars; + @Getter private final Int2ObjectMap avatars; private final Long2ObjectMap avatarsGuid; public AvatarStorage(Player player) { @@ -28,10 +29,6 @@ public AvatarStorage(Player player) { this.avatarsGuid = new Long2ObjectOpenHashMap<>(); } - public Int2ObjectMap getAvatars() { - return avatars; - } - public int getAvatarCount() { return this.avatars.size(); } diff --git a/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java b/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java index 0d48355a557..6b2ca8a054b 100644 --- a/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java +++ b/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java @@ -103,7 +103,7 @@ public Map getMissions() { // Will return a new empty mission if the mission id is not found public BattlePassMission loadMissionById(int id) { - return getMissions().computeIfAbsent(id, i -> new BattlePassMission(i)); + return getMissions().computeIfAbsent(id, BattlePassMission::new); } public boolean hasMission(int id) { @@ -176,7 +176,7 @@ public void takeMissionPoint(List missionIdList) { private void takeRewardsFromSelectChest( ItemData rewardItemData, int index, ItemParamData entry, List rewardItems) { // Sanity checks. - if (rewardItemData.getItemUse().size() < 1) { + if (rewardItemData.getItemUse().isEmpty()) { return; } diff --git a/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java b/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java index afd895224ee..f5b0b109701 100644 --- a/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java +++ b/src/main/java/emu/grasscutter/game/battlepass/BattlePassMission.java @@ -4,12 +4,14 @@ import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.BattlePassMissionData; import emu.grasscutter.game.props.BattlePassMissionStatus; +import lombok.Getter; +import lombok.Setter; @Entity public class BattlePassMission { - private int id; - private int progress; - private BattlePassMissionStatus status; + @Getter private int id; + @Setter @Getter private int progress; + @Setter private BattlePassMissionStatus status; @Transient private BattlePassMissionData data; @@ -20,10 +22,6 @@ public BattlePassMission(int id) { this.id = id; } - public int getId() { - return id; - } - public BattlePassMissionData getData() { if (this.data == null) { this.data = GameData.getBattlePassMissionDataMap().get(getId()); @@ -31,14 +29,6 @@ public BattlePassMissionData getData() { return this.data; } - public int getProgress() { - return progress; - } - - public void setProgress(int value) { - this.progress = value; - } - public void addProgress(int addProgress, int maxProgress) { this.progress = Math.min(addProgress + this.progress, maxProgress); } @@ -48,10 +38,6 @@ public BattlePassMissionStatus getStatus() { return status; } - public void setStatus(BattlePassMissionStatus status) { - this.status = status; - } - public boolean isFinshed() { return getStatus().getValue() >= 2; } diff --git a/src/main/java/emu/grasscutter/game/battlepass/BattlePassReward.java b/src/main/java/emu/grasscutter/game/battlepass/BattlePassReward.java index 6433563d736..b25b4ff9652 100644 --- a/src/main/java/emu/grasscutter/game/battlepass/BattlePassReward.java +++ b/src/main/java/emu/grasscutter/game/battlepass/BattlePassReward.java @@ -4,12 +4,13 @@ import emu.grasscutter.data.excels.BattlePassMissionData; import emu.grasscutter.net.proto.BattlePassRewardTagOuterClass.BattlePassRewardTag; import emu.grasscutter.net.proto.BattlePassUnlockStatusOuterClass.BattlePassUnlockStatus; +import lombok.Getter; @Entity public class BattlePassReward { - private int level; - private int rewardId; - private boolean paid; + @Getter private int level; + @Getter private int rewardId; + @Getter private boolean paid; @Transient private BattlePassMissionData data; @@ -22,18 +23,6 @@ public BattlePassReward(int level, int rewardId, boolean paid) { this.paid = paid; } - public int getLevel() { - return level; - } - - public int getRewardId() { - return rewardId; - } - - public boolean isPaid() { - return paid; - } - public BattlePassRewardTag toProto() { var protoBuilder = BattlePassRewardTag.newBuilder(); diff --git a/src/main/java/emu/grasscutter/game/chat/ChatSystem.java b/src/main/java/emu/grasscutter/game/chat/ChatSystem.java index dd86b05686c..220cdad6554 100644 --- a/src/main/java/emu/grasscutter/game/chat/ChatSystem.java +++ b/src/main/java/emu/grasscutter/game/chat/ChatSystem.java @@ -12,6 +12,7 @@ import emu.grasscutter.utils.Utils; import java.util.*; import java.util.regex.Pattern; +import lombok.Getter; public class ChatSystem implements ChatSystemHandler { static final String PREFIXES = "[/!]"; @@ -22,16 +23,12 @@ public class ChatSystem implements ChatSystemHandler { // user id -> chat partner id -> [messages] private final Map>> history = new HashMap<>(); - private final GameServer server; + @Getter private final GameServer server; public ChatSystem(GameServer server) { this.server = server; } - public GameServer getServer() { - return server; - } - private boolean tryInvokeCommand(Player sender, Player target, String rawMessage) { if (!RE_PREFIXES.matcher(rawMessage.substring(0, 1)).matches()) return false; for (String line : rawMessage.substring(1).split("\n[/!]")) @@ -88,7 +85,7 @@ public void handlePullRecentChatReq(Player player) { ********************/ public void sendPrivateMessageFromServer(int targetUid, String message) { // Sanity checks. - if (message == null || message.length() == 0) { + if (message == null || message.isEmpty()) { return; } @@ -123,7 +120,7 @@ public void sendPrivateMessageFromServer(int targetUid, int emote) { public void sendPrivateMessage(Player player, int targetUid, String message) { // Sanity checks. - if (message == null || message.length() == 0) { + if (message == null || message.isEmpty()) { return; } @@ -146,7 +143,7 @@ public void sendPrivateMessage(Player player, int targetUid, String message) { // Fetch the new message. message = event.getMessage(); - if (message == null || message.length() == 0) return; + if (message == null || message.isEmpty()) return; // Create chat packet. var packet = new PacketPrivateChatNotify(player.getUid(), targetUid, message); @@ -200,7 +197,7 @@ public void sendPrivateMessage(Player player, int targetUid, int emote) { public void sendTeamMessage(Player player, int channel, String message) { // Sanity checks - if (message == null || message.length() == 0) { + if (message == null || message.isEmpty()) { return; } @@ -216,7 +213,7 @@ public void sendTeamMessage(Player player, int channel, String message) { // Fetch the new message. message = event.getMessage(); - if (message == null || message.length() == 0) return; + if (message == null || message.isEmpty()) return; // Fetch the new channel. channel = event.getChannel(); if (channel == -1) return; @@ -254,7 +251,7 @@ private void sendServerWelcomeMessages(Player player) { joinOptions.welcomeEmotes[Utils.randomRange(0, joinOptions.welcomeEmotes.length - 1)]); } - if (joinOptions.welcomeMessage != null && joinOptions.welcomeMessage.length() > 0) { + if (joinOptions.welcomeMessage != null && !joinOptions.welcomeMessage.isEmpty()) { this.sendPrivateMessageFromServer(player.getUid(), joinOptions.welcomeMessage); } } diff --git a/src/main/java/emu/grasscutter/game/city/CityInfoData.java b/src/main/java/emu/grasscutter/game/city/CityInfoData.java index 5c8bde72fd0..e9fa10657a1 100644 --- a/src/main/java/emu/grasscutter/game/city/CityInfoData.java +++ b/src/main/java/emu/grasscutter/game/city/CityInfoData.java @@ -4,14 +4,15 @@ import emu.grasscutter.net.proto.CityInfoOuterClass.CityInfo; import lombok.*; +@Setter +@Getter @Entity public class CityInfoData { - @Getter @Setter private int cityId; + private int cityId; - @Getter @Setter private int level = 1; // level of the city (include level SotS, level Frostbearing Trees, etc.) - @Getter @Setter private int numCrystal = 0; // number of crystals in the city + private int numCrystal = 0; // number of crystals in the city public CityInfoData(int cityId) { this.cityId = cityId; diff --git a/src/main/java/emu/grasscutter/game/combine/CombineManger.java b/src/main/java/emu/grasscutter/game/combine/CombineManger.java index 08305cae10d..61baedec076 100644 --- a/src/main/java/emu/grasscutter/game/combine/CombineManger.java +++ b/src/main/java/emu/grasscutter/game/combine/CombineManger.java @@ -27,10 +27,7 @@ public static void initialize() { // Read the data we need for strongbox. try { DataLoader.loadList("ReliquaryDecompose.json", ReliquaryDecomposeEntry.class) - .forEach( - entry -> { - reliquaryDecomposeData.put(entry.getConfigId(), entry.getItems()); - }); + .forEach(entry -> reliquaryDecomposeData.put(entry.getConfigId(), entry.getItems())); Grasscutter.getLogger() .debug("Loaded {} reliquary decompose entries.", reliquaryDecomposeData.size()); } catch (Exception ex) { diff --git a/src/main/java/emu/grasscutter/game/combine/CombineResult.java b/src/main/java/emu/grasscutter/game/combine/CombineResult.java index df8ace74b3b..1fc4db3cc35 100644 --- a/src/main/java/emu/grasscutter/game/combine/CombineResult.java +++ b/src/main/java/emu/grasscutter/game/combine/CombineResult.java @@ -2,42 +2,14 @@ import emu.grasscutter.data.common.ItemParamData; import java.util.List; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class CombineResult { private List material; private List result; private List extra; private List back; - - public List getMaterial() { - return material; - } - - public void setMaterial(List material) { - this.material = material; - } - - public List getResult() { - return result; - } - - public void setResult(List result) { - this.result = result; - } - - public List getExtra() { - return extra; - } - - public void setExtra(List extra) { - this.extra = extra; - } - - public List getBack() { - return back; - } - - public void setBack(List back) { - this.back = back; - } } diff --git a/src/main/java/emu/grasscutter/game/combine/ReliquaryDecomposeEntry.java b/src/main/java/emu/grasscutter/game/combine/ReliquaryDecomposeEntry.java index 856278535c2..40d576bf01e 100644 --- a/src/main/java/emu/grasscutter/game/combine/ReliquaryDecomposeEntry.java +++ b/src/main/java/emu/grasscutter/game/combine/ReliquaryDecomposeEntry.java @@ -1,24 +1,12 @@ package emu.grasscutter.game.combine; import java.util.List; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class ReliquaryDecomposeEntry { private int configId; private List items; - - public int getConfigId() { - return configId; - } - - public void setConfigId(int configId) { - this.configId = configId; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } } diff --git a/src/main/java/emu/grasscutter/game/drop/DropData.java b/src/main/java/emu/grasscutter/game/drop/DropData.java index e82681f5913..6c8cec4ab6b 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropData.java +++ b/src/main/java/emu/grasscutter/game/drop/DropData.java @@ -1,50 +1,18 @@ package emu.grasscutter.game.drop; +import lombok.Getter; +import lombok.Setter; + +@Getter @Deprecated public class DropData { private int minWeight; private int maxWeight; - private int itemId; + @Setter private int itemId; private int minCount; private int maxCount; private boolean share = false; - private boolean give = false; - - public boolean isGive() { - return give; - } - - public void setGive(boolean give) { - this.give = give; - } - - public int getItemId() { - return itemId; - } - - public void setItemId(int itemId) { - this.itemId = itemId; - } - - public int getMinCount() { - return minCount; - } - - public int getMaxCount() { - return maxCount; - } - - public int getMinWeight() { - return minWeight; - } - - public int getMaxWeight() { - return maxWeight; - } - - public boolean isShare() { - return share; - } + @Setter private boolean give = false; public void setIsShare(boolean share) { this.share = share; diff --git a/src/main/java/emu/grasscutter/game/drop/DropInfo.java b/src/main/java/emu/grasscutter/game/drop/DropInfo.java index 0484d777a4e..afdca351b38 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropInfo.java +++ b/src/main/java/emu/grasscutter/game/drop/DropInfo.java @@ -1,17 +1,11 @@ package emu.grasscutter.game.drop; import java.util.List; +import lombok.Getter; +@Getter @SuppressWarnings("deprecation") public class DropInfo { private int monsterId; private List dropDataList; - - public int getMonsterId() { - return monsterId; - } - - public List getDropDataList() { - return dropDataList; - } } diff --git a/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java b/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java index d0167ab404a..b65708687bc 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java +++ b/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java @@ -12,7 +12,9 @@ import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.*; import java.util.List; +import lombok.Getter; +@Getter @SuppressWarnings("deprecation") public class DropSystemLegacy extends BaseGameSystem { private final Int2ObjectMap> dropData; @@ -23,15 +25,11 @@ public DropSystemLegacy(GameServer server) { this.load(); } - public Int2ObjectMap> getDropData() { - return dropData; - } - public synchronized void load() { getDropData().clear(); try { List banners = DataLoader.loadList("Drop.json", DropInfo.class); - if (banners.size() > 0) { + if (!banners.isEmpty()) { for (DropInfo di : banners) { getDropData().put(di.getMonsterId(), di.getDropDataList()); } diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonDrop.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonDrop.java index f329eab9ced..7c9f7c1a22c 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonDrop.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonDrop.java @@ -1,24 +1,12 @@ package emu.grasscutter.game.dungeons; import java.util.List; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class DungeonDrop { private int dungeonId; private List drops; - - public int getDungeonId() { - return dungeonId; - } - - public void setDungeonId(int dungeonId) { - this.dungeonId = dungeonId; - } - - public List getDrops() { - return drops; - } - - public void setDrops(List drops) { - this.drops = drops; - } } diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonDropEntry.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonDropEntry.java index 80e7b80af7e..60efe56d94a 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonDropEntry.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonDropEntry.java @@ -1,51 +1,15 @@ package emu.grasscutter.game.dungeons; import java.util.List; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class DungeonDropEntry { private List counts; private List items; private List probabilities; private List itemProbabilities; private boolean mpDouble; - - public List getCounts() { - return counts; - } - - public void setCounts(List counts) { - this.counts = counts; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public List getProbabilities() { - return probabilities; - } - - public void setProbabilities(List probabilities) { - this.probabilities = probabilities; - } - - public List getItemProbabilities() { - return itemProbabilities; - } - - public void setItemProbabilities(List itemProbabilities) { - this.itemProbabilities = itemProbabilities; - } - - public boolean isMpDouble() { - return mpDouble; - } - - public void setMpDouble(boolean mpDouble) { - this.mpDouble = mpDouble; - } } diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java index f22eb78dc08..8c6d1a28861 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonEndStats.java @@ -3,11 +3,12 @@ import emu.grasscutter.game.dungeons.dungeon_results.BaseDungeonResult; import lombok.Getter; +@Getter public class DungeonEndStats { - @Getter private int killedMonsters; - @Getter private int timeTaken; - @Getter private int openChestCount; - @Getter private BaseDungeonResult.DungeonEndReason dungeonResult; + private final int killedMonsters; + private final int timeTaken; + private final int openChestCount; + private final BaseDungeonResult.DungeonEndReason dungeonResult; public DungeonEndStats( int killedMonsters, diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java index ee56a873c74..cefca5e8165 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java @@ -8,7 +8,6 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.world.*; -import emu.grasscutter.net.packet.*; import emu.grasscutter.server.game.*; import emu.grasscutter.server.packet.send.PacketDungeonEntryInfoRsp; import it.unimi.dsi.fastutil.ints.*; @@ -68,7 +67,7 @@ public void sendEntryInfoFor(Player player, int pointId, int sceneId) { // Check if the player has quests with dungeon IDs. var questDungeons = player.getQuestManager().questsForDungeon(entry); - if (questDungeons.size() > 0) { + if (!questDungeons.isEmpty()) { player.sendPacket(new PacketDungeonEntryInfoRsp(entry.getPointData(), questDungeons)); } else { player.sendPacket(new PacketDungeonEntryInfoRsp(entry.getPointData())); diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java index 86a27021b75..adeef9d21b0 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/DungeonChallenge.java @@ -4,9 +4,13 @@ import emu.grasscutter.game.dungeons.enums.DungeonPassConditionType; import emu.grasscutter.game.world.Scene; import emu.grasscutter.scripts.data.SceneGroup; +import lombok.Getter; +import lombok.Setter; import java.util.List; +@Setter +@Getter public final class DungeonChallenge extends WorldChallenge { /** @@ -22,14 +26,6 @@ public DungeonChallenge(Scene scene, SceneGroup group, super(scene, group, challengeId, challengeIndex, paramList, timeLimit, goal, challengeTriggers); } - public boolean isStage() { - return stage; - } - - public void setStage(boolean stage) { - this.stage = stage; - } - @Override public void done() { super.done(); diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java index f2d4c63ae98..8be4662864f 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java @@ -29,8 +29,8 @@ public WorldChallenge build( Scene scene, SceneGroup group) { val realGroup = scene.getScriptManager().getGroupById(groupId); - val challengeTriggers = new ArrayList(); - challengeTriggers.addAll(List.of(new KillMonsterCountTrigger(), new InTimeTrigger())); + val challengeTriggers = + new ArrayList<>(List.of(new KillMonsterCountTrigger(), new InTimeTrigger())); val challengeData = GameData.getDungeonChallengeConfigDataMap().get(challengeId); val challengeType = challengeData.getChallengeType(); diff --git a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java index 367c6baa1c9..08c271ff608 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java +++ b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/BaseDungeonResult.java @@ -7,9 +7,10 @@ import emu.grasscutter.utils.Utils; import lombok.Getter; +@Getter public class BaseDungeonResult { - @Getter DungeonData dungeonData; - @Getter DungeonEndStats dungeonStats; + DungeonData dungeonData; + DungeonEndStats dungeonStats; public BaseDungeonResult(DungeonData dungeonData, DungeonEndStats dungeonStats) { this.dungeonData = dungeonData; diff --git a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java index b42e041ec8c..1c87e908f58 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java +++ b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TowerResult.java @@ -9,11 +9,11 @@ import emu.grasscutter.net.proto.TowerLevelEndNotifyOuterClass.TowerLevelEndNotify.ContinueStateType; public class TowerResult extends BaseDungeonResult { - WorldChallenge challenge; - boolean canJump; - boolean hasNextLevel; - int nextFloorId; - int currentStars; + final WorldChallenge challenge; + final boolean canJump; + final boolean hasNextLevel; + final int nextFloorId; + final int currentStars; public TowerResult( DungeonData dungeonData, diff --git a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java index dd20fec4947..c344d4d904a 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java +++ b/src/main/java/emu/grasscutter/game/dungeons/dungeon_results/TrialAvatarDungeonResult.java @@ -6,7 +6,7 @@ import emu.grasscutter.net.proto.TrialAvatarFirstPassDungeonNotifyOuterClass.TrialAvatarFirstPassDungeonNotify; public class TrialAvatarDungeonResult extends BaseDungeonResult { - int trialCharacterIndexId; + final int trialCharacterIndexId; public TrialAvatarDungeonResult( DungeonData dungeonData, DungeonEndStats dungeonStats, int trialCharacterIndexId) { diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java index cfd1a47eea9..a28e445e61a 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonPassConditionType.java @@ -3,6 +3,7 @@ import emu.grasscutter.scripts.constants.IntValueEnum; import lombok.Getter; +@Getter public enum DungeonPassConditionType implements IntValueEnum { DUNGEON_COND_NONE(0), DUNGEON_COND_KILL_MONSTER(3), @@ -15,7 +16,7 @@ public enum DungeonPassConditionType implements IntValueEnum { DUNGEON_COND_END_MULTISTAGE_PLAY(15) // Missing ; - @Getter private final int id; + private final int id; DungeonPassConditionType(int id) { this.id = id; diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java index a5b5993fa37..78c5de72fda 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/DungeonType.java @@ -2,6 +2,7 @@ import lombok.Getter; +@Getter public enum DungeonType { DUNGEON_NONE(false), DUNGEON_PLOT(true), @@ -41,7 +42,7 @@ public enum DungeonType { DUNGEON_EFFIGY_CHALLENGE_V2(false), DUNGEON_CHAR_AMUSEMENT(false); - @Getter private final boolean countsToBattlepass; + private final boolean countsToBattlepass; DungeonType(boolean countsToBattlepass) { this.countsToBattlepass = countsToBattlepass; diff --git a/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java b/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java index 1a591408c3d..6bf6d1b4fc0 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java +++ b/src/main/java/emu/grasscutter/game/dungeons/enums/SettleShowType.java @@ -2,6 +2,7 @@ import lombok.Getter; +@Getter public enum SettleShowType { SETTLE_SHOW_NONE(0), SETTLE_SHOW_TIME_COST(1), @@ -9,7 +10,7 @@ public enum SettleShowType { SETTLE_SHOW_KILL_MONSTER_COUNT(3), SETTLE_SHOW_BLACKSCREEN(4); - @Getter private final int id; + private final int id; SettleShowType(int id) { this.id = id; diff --git a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java index 2bff768bae6..764f7e42626 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java @@ -33,11 +33,12 @@ import it.unimi.dsi.fastutil.ints.Int2FloatMap; import lombok.*; +@Getter public class EntityAvatar extends GameEntity { - @Getter private final Avatar avatar; + private final Avatar avatar; - @Getter private PlayerDieType killedType; - @Getter private int killedBy; + private PlayerDieType killedType; + private int killedBy; public EntityAvatar(Avatar avatar) { this(null, avatar); @@ -363,7 +364,7 @@ public AbilityControlBlock getAbilityControlBlock() { } } // Add equip abilities - if (this.getAvatar().getExtraAbilityEmbryos().size() > 0) { + if (!this.getAvatar().getExtraAbilityEmbryos().isEmpty()) { for (String skill : this.getAvatar().getExtraAbilityEmbryos()) { AbilityEmbryo emb = AbilityEmbryo.newBuilder() diff --git a/src/main/java/emu/grasscutter/game/entity/EntityClientGadget.java b/src/main/java/emu/grasscutter/game/entity/EntityClientGadget.java index 8296c09c917..740e46f60ac 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityClientGadget.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityClientGadget.java @@ -29,13 +29,13 @@ public class EntityClientGadget extends EntityBaseGadget { @Getter private final Player owner; @Getter(onMethod_ = @Override) - private int gadgetId; + private final int gadgetId; - @Getter private int ownerEntityId; - @Getter private int targetEntityId; - @Getter private boolean asyncLoad; + @Getter private final int ownerEntityId; + @Getter private final int targetEntityId; + @Getter private final boolean asyncLoad; - @Getter private int originalOwnerEntityId; + @Getter private final int originalOwnerEntityId; @Getter private final GadgetData gadgetData; private ConfigEntityGadget configGadget; diff --git a/src/main/java/emu/grasscutter/game/entity/EntityItem.java b/src/main/java/emu/grasscutter/game/entity/EntityItem.java index 3946ab3f30f..5da3705033a 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityItem.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityItem.java @@ -26,10 +26,11 @@ import it.unimi.dsi.fastutil.ints.Int2FloatMap; import lombok.Getter; +@Getter public class EntityItem extends EntityBaseGadget { - @Getter private final GameItem item; - @Getter private final long guid; - @Getter private final boolean share; + private final GameItem item; + private final long guid; + private final boolean share; public EntityItem(Scene scene, Player player, ItemData itemData, Position pos, int count) { this(scene, player, itemData, pos, count, true); diff --git a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java index f60f17c13af..37392a3e897 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java @@ -50,13 +50,13 @@ public class EntityMonster extends GameEntity { @Getter private final Position bornPos; @Getter private final int level; @Getter private EntityWeapon weaponEntity; - @Getter private Map summonTagMap; + @Getter private final Map summonTagMap; @Getter @Setter private int summonedTag; @Getter @Setter private int ownerEntityId; @Getter @Setter private int poseId; @Getter @Setter private int aiId = -1; - @Getter private List playerOnBattle; + @Getter private final List playerOnBattle; @Nullable @Getter @Setter private SceneMonster metaMonster; public EntityMonster( diff --git a/src/main/java/emu/grasscutter/game/entity/EntityRegion.java b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java index 37be6f3b9b4..0bb4cfb6898 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityRegion.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java @@ -82,7 +82,7 @@ public Position getRotation() { @Override public SceneEntityInfoOuterClass.SceneEntityInfo toProto() { - /** The Region Entity would not be sent to client. */ + /* The Region Entity would not be sent to client. */ return null; } diff --git a/src/main/java/emu/grasscutter/game/entity/EntitySolarIsotomaClientGadget.java b/src/main/java/emu/grasscutter/game/entity/EntitySolarIsotomaClientGadget.java index 9d3e13cdb6c..981bd1fa6a1 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntitySolarIsotomaClientGadget.java +++ b/src/main/java/emu/grasscutter/game/entity/EntitySolarIsotomaClientGadget.java @@ -6,10 +6,11 @@ import emu.grasscutter.net.proto.EvtCreateGadgetNotifyOuterClass; import lombok.Getter; +@Getter public class EntitySolarIsotomaClientGadget extends EntityClientGadget { public static final int GADGET_ID = 41038001; public static final int ELEVATOR_GADGET_ID = 41038002; - @Getter private EntityGadget platformGadget; + private EntityGadget platformGadget; public EntitySolarIsotomaClientGadget( Scene scene, Player player, EvtCreateGadgetNotifyOuterClass.EvtCreateGadgetNotify notify) { diff --git a/src/main/java/emu/grasscutter/game/entity/EntityTeam.java b/src/main/java/emu/grasscutter/game/entity/EntityTeam.java index 949b003ab65..a7b5418911c 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityTeam.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityTeam.java @@ -10,7 +10,7 @@ public class EntityTeam extends GameEntity { - private Player player; + private final Player player; public EntityTeam(Player player) { super(player.getScene()); diff --git a/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java b/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java index 88db87bfa3c..78a3df4eeb9 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityVehicle.java @@ -36,7 +36,7 @@ public class EntityVehicle extends EntityBaseGadget { @Getter private final int gadgetId; @Getter @Setter private float curStamina; - @Getter private List vehicleMembers; + @Getter private final List vehicleMembers; @Nullable @Getter private ConfigEntityGadget configGadget; public EntityVehicle( diff --git a/src/main/java/emu/grasscutter/game/entity/EntityWorld.java b/src/main/java/emu/grasscutter/game/entity/EntityWorld.java index 50692cd72db..586e6b386f9 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityWorld.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityWorld.java @@ -7,8 +7,9 @@ import it.unimi.dsi.fastutil.ints.*; import lombok.Getter; +@Getter public class EntityWorld extends GameEntity { - @Getter private World world; + private final World world; public EntityWorld(World world) { super(null); diff --git a/src/main/java/emu/grasscutter/game/entity/GameEntity.java b/src/main/java/emu/grasscutter/game/entity/GameEntity.java index 7e78dbb100f..e3b9003ffbf 100644 --- a/src/main/java/emu/grasscutter/game/entity/GameEntity.java +++ b/src/main/java/emu/grasscutter/game/entity/GameEntity.java @@ -44,13 +44,13 @@ public abstract class GameEntity { @Getter @Setter private EntityController entityController; @Getter private ElementType lastAttackType = ElementType.None; - @Getter private List instancedAbilities = new ArrayList<>(); + @Getter private final List instancedAbilities = new ArrayList<>(); @Getter - private Int2ObjectMap instancedModifiers = + private final Int2ObjectMap instancedModifiers = new Int2ObjectOpenHashMap<>(); - @Getter private Map globalAbilityValues = new HashMap<>(); + @Getter private final Map globalAbilityValues = new HashMap<>(); public GameEntity(Scene scene) { this.scene = scene; diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java index 3fc91e587bc..6775ea4caf7 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetAbility.java @@ -8,7 +8,7 @@ import lombok.val; public class GadgetAbility extends GadgetContent { - private EntityBaseGadget parent; + private final EntityBaseGadget parent; public GadgetAbility(EntityGadget gadget, EntityBaseGadget parent) { super(gadget); diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetContent.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetContent.java index 0919578328e..01208e30175 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetContent.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetContent.java @@ -4,7 +4,9 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq; import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo; +import lombok.Getter; +@Getter public abstract class GadgetContent { private final EntityGadget gadget; @@ -12,10 +14,6 @@ public GadgetContent(EntityGadget gadget) { this.gadget = gadget; } - public EntityGadget getGadget() { - return gadget; - } - public abstract boolean onInteract(Player player, GadgetInteractReq req); public abstract void onBuildProto(SceneGadgetInfo.Builder gadgetInfo); diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java index 03aab7d2757..2cecac1f9de 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java @@ -16,9 +16,10 @@ import emu.grasscutter.scripts.data.ScriptArgs; import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp; import emu.grasscutter.utils.Utils; +import lombok.Getter; public final class GadgetGatherObject extends GadgetContent { - private int itemId; + @Getter private int itemId; private boolean isForbidGuest; public GadgetGatherObject(EntityGadget gadget) { @@ -39,10 +40,6 @@ public GadgetGatherObject(EntityGadget gadget) { } } - public int getItemId() { - return this.itemId; - } - public boolean isForbidGuest() { return isForbidGuest; } diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java index 0575e2ad920..5786cb38437 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/BaseRoute.java @@ -6,12 +6,14 @@ import emu.grasscutter.scripts.data.SceneGadget; import lombok.*; +@Setter +@Getter public abstract class BaseRoute { - @Getter @Setter private boolean isStarted; - @Getter @Setter private boolean isActive; - @Getter @Setter private Position startRot; - @Getter @Setter private int startSceneTime; - @Getter @Setter private int stopSceneTime; + private boolean isStarted; + private boolean isActive; + private Position startRot; + private int startSceneTime; + private int stopSceneTime; BaseRoute(Position startRot, boolean isStarted, boolean isActive) { this.startRot = startRot; diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java index a70a8e769a1..b79f10ca468 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/ConfigRoute.java @@ -6,11 +6,13 @@ import java.util.*; import lombok.*; +@Setter +@Getter public class ConfigRoute extends BaseRoute { - @Getter @Setter private int routeId; - @Getter @Setter private int startIndex; - @Getter @Setter private List scheduledIndexes; + private int routeId; + private int startIndex; + private List scheduledIndexes; public ConfigRoute(SceneGadget gadget) { super(gadget); diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java b/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java index cd0c67efe49..b3455e739f5 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/platform/PointArrayRoute.java @@ -6,10 +6,12 @@ import lombok.*; /** TODO implement point array routes, read from missing resources */ +@Setter +@Getter public class PointArrayRoute extends BaseRoute { - @Getter @Setter int currentPoint; - @Getter @Setter int pointArrayId; + int currentPoint; + int pointArrayId; public PointArrayRoute(SceneGadget gadget) { super(gadget); diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java index 8d322794da7..37299e27c9f 100644 --- a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java @@ -4,10 +4,11 @@ import emu.grasscutter.utils.Utils; import lombok.Getter; +@Getter public class ExpeditionRewardData { - @Getter private int itemId; - @Getter private int minCount; - @Getter private int maxCount; + private int itemId; + private int minCount; + private int maxCount; public GameItem getReward() { return new GameItem(itemId, Utils.randomRange(minCount, maxCount)); diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java index 2712bfd27f2..0851abfc8fb 100644 --- a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java @@ -4,9 +4,10 @@ import java.util.*; import lombok.Getter; +@Getter public class ExpeditionRewardDataList { - @Getter private int hourTime; - @Getter private List expeditionRewardData; + private int hourTime; + private List expeditionRewardData; public List getRewards() { List rewards = new ArrayList<>(); diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java index b39475b836b..8685ceddceb 100644 --- a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java @@ -3,7 +3,8 @@ import java.util.List; import lombok.Getter; +@Getter public class ExpeditionRewardInfo { - @Getter private int expId; - @Getter private List expeditionRewardDataList; + private int expId; + private List expeditionRewardDataList; } diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionSystem.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionSystem.java index d58d4cf6213..b2fa5916f58 100644 --- a/src/main/java/emu/grasscutter/game/expedition/ExpeditionSystem.java +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionSystem.java @@ -24,7 +24,7 @@ public synchronized void load() { try { List banners = DataLoader.loadList("ExpeditionReward.json", ExpeditionRewardInfo.class); - if (banners.size() > 0) { + if (!banners.isEmpty()) { for (ExpeditionRewardInfo di : banners) { getExpeditionRewardDataList().put(di.getExpId(), di.getExpeditionRewardDataList()); } diff --git a/src/main/java/emu/grasscutter/game/friends/FriendsList.java b/src/main/java/emu/grasscutter/game/friends/FriendsList.java index f7b1cd0f8f3..2dab4da1b07 100644 --- a/src/main/java/emu/grasscutter/game/friends/FriendsList.java +++ b/src/main/java/emu/grasscutter/game/friends/FriendsList.java @@ -15,8 +15,8 @@ public class FriendsList extends BasePlayerManager { public FriendsList(Player player) { super(player); - this.friends = new Int2ObjectOpenHashMap(); - this.pendingFriends = new Int2ObjectOpenHashMap(); + this.friends = new Int2ObjectOpenHashMap<>(); + this.pendingFriends = new Int2ObjectOpenHashMap<>(); } public boolean hasLoaded() { @@ -93,8 +93,8 @@ public synchronized void handleFriendRequest(int targetUid, DealAddFriendResultT // Handle if (result == DealAddFriendResultType.DEAL_ADD_FRIEND_RESULT_TYPE_ACCEPT) { // Request accepted - myFriendship.setIsFriend(true); - theirFriendship.setIsFriend(true); + myFriendship.setFriend(true); + theirFriendship.setFriend(true); this.getPendingFriends().remove(myFriendship.getOwnerId()); this.addFriend(myFriendship); diff --git a/src/main/java/emu/grasscutter/game/friends/Friendship.java b/src/main/java/emu/grasscutter/game/friends/Friendship.java index 21d483a29a4..43c924578eb 100644 --- a/src/main/java/emu/grasscutter/game/friends/Friendship.java +++ b/src/main/java/emu/grasscutter/game/friends/Friendship.java @@ -7,18 +7,20 @@ import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; import emu.grasscutter.net.proto.PlatformTypeOuterClass; import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; +import lombok.Getter; +import lombok.Setter; import org.bson.types.ObjectId; @Entity(value = "friendships", useDiscriminator = false) public class Friendship { @Id private ObjectId id; - @Transient private Player owner; + @Setter @Getter @Transient private Player owner; - @Indexed private int ownerId; - @Indexed private int friendId; - private boolean isFriend; - private int askerId; + @Getter @Indexed private int ownerId; + @Getter @Indexed private int friendId; + @Setter private boolean isFriend; + @Setter @Getter private int askerId; private PlayerProfile profile; @@ -33,38 +35,10 @@ public Friendship(Player owner, Player friend, Player asker) { this.askerId = asker.getUid(); } - public Player getOwner() { - return owner; - } - - public void setOwner(Player owner) { - this.owner = owner; - } - public boolean isFriend() { return isFriend; } - public void setIsFriend(boolean b) { - this.isFriend = b; - } - - public int getOwnerId() { - return ownerId; - } - - public int getFriendId() { - return friendId; - } - - public int getAskerId() { - return askerId; - } - - public void setAskerId(int askerId) { - this.askerId = askerId; - } - public PlayerProfile getFriendProfile() { return profile; } diff --git a/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java b/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java index 6d150df5f47..50991444637 100644 --- a/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java +++ b/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java @@ -24,8 +24,8 @@ public class PlayerProfile { private int worldLevel; private int lastActiveTime; - private boolean isInDuel = false; // TODO: Implement duels. (TCG) - private boolean isDuelObservable = false; // TODO: Implement duels. (TCG) + private final boolean isInDuel = false; // TODO: Implement duels. (TCG) + private final boolean isDuelObservable = false; // TODO: Implement duels. (TCG) @Getter private int enterHomeOption; diff --git a/src/main/java/emu/grasscutter/game/gacha/GachaBanner.java b/src/main/java/emu/grasscutter/game/gacha/GachaBanner.java index b1bdaeef2b0..3b3d2c6a382 100644 --- a/src/main/java/emu/grasscutter/game/gacha/GachaBanner.java +++ b/src/main/java/emu/grasscutter/game/gacha/GachaBanner.java @@ -39,24 +39,24 @@ public class GachaBanner { @Getter private String previewPrefabPath; @Getter private String titlePath; private int costItemId = 0; - private int costItemAmount = 1; + private final int costItemAmount = 1; private int costItemId10 = 0; - private int costItemAmount10 = 10; - @Getter private int beginTime = 0; - @Getter private int endTime = 1924992000; - @Getter private int gachaTimesLimit = Integer.MAX_VALUE; - @Getter private int[] rateUpItems4 = {}; - @Getter private int[] rateUpItems5 = {}; + private final int costItemAmount10 = 10; + @Getter private final int beginTime = 0; + @Getter private final int endTime = 1924992000; + @Getter private final int gachaTimesLimit = Integer.MAX_VALUE; + @Getter private final int[] rateUpItems4 = {}; + @Getter private final int[] rateUpItems5 = {}; // This now handles default values for the fields below - @Getter private BannerType bannerType = BannerType.STANDARD; + @Getter private final BannerType bannerType = BannerType.STANDARD; // These don't change between banner types (apart from Standard having three extra 4star avatars) @Getter - private int[] fallbackItems3 = { + private final int[] fallbackItems3 = { 11301, 11302, 11306, 12301, 12302, 12305, 13303, 14301, 14302, 14304, 15301, 15302, 15304 }; - @Getter private int[] fallbackItems4Pool1 = DEFAULT_FALLBACK_ITEMS_4_POOL_1; - @Getter private int[] fallbackItems4Pool2 = DEFAULT_FALLBACK_ITEMS_4_POOL_2; + @Getter private final int[] fallbackItems4Pool1 = DEFAULT_FALLBACK_ITEMS_4_POOL_1; + @Getter private final int[] fallbackItems4Pool2 = DEFAULT_FALLBACK_ITEMS_4_POOL_2; // Different banner types have different defaults, see above for default values and the enum for // which are used where. @Getter private int[] fallbackItems5Pool1; @@ -66,42 +66,40 @@ public class GachaBanner { private int eventChance4 = -1; // Chance to win a featured event item private int eventChance5 = -1; // Chance to win a featured event item // - @Getter private boolean removeC6FromPool = false; + @Getter private final boolean removeC6FromPool = false; @Getter - private boolean autoStripRateUpFromFallback = + private final boolean autoStripRateUpFromFallback = true; // Ensures that featured items won't "double dip" into the losing pool - private int[][] poolBalanceWeights4 = { + private final int[][] poolBalanceWeights4 = { {1, 255}, {17, 255}, {21, 10455} }; // Used to ensure that players won't go too many rolls without getting something from pool 1 // (avatar) or pool 2 (weapon) - private int[][] poolBalanceWeights5 = {{1, 30}, {147, 150}, {181, 10230}}; - @Getter private int wishMaxProgress = 2; + private final int[][] poolBalanceWeights5 = {{1, 30}, {147, 150}, {181, 10230}}; + @Getter private final int wishMaxProgress = 2; // Deprecated fields that were tolerated in early May 2022 but have apparently still being // circulating in new custom configs // For now, throw up big scary errors on load telling people that they will be banned outright in // a future version - @Deprecated private int[] rateUpItems1 = {}; - @Deprecated private int[] rateUpItems2 = {}; - @Deprecated private int eventChance = -1; - @Deprecated private int costItem = 0; - @Deprecated private int softPity = -1; - @Deprecated private int hardPity = -1; - @Deprecated private int minItemType = -1; - @Deprecated private int maxItemType = -1; + @Deprecated private final int[] rateUpItems1 = {}; + @Deprecated private final int[] rateUpItems2 = {}; + @Deprecated private final int eventChance = -1; + @Deprecated private final int costItem = 0; + @Deprecated private final int softPity = -1; + @Deprecated private final int hardPity = -1; + @Deprecated private final int minItemType = -1; + @Deprecated private final int maxItemType = -1; @Getter private boolean deprecated = false; - @Getter private boolean disabled = false; + @Getter private final boolean disabled = false; private void warnDeprecated(String name, String replacement) { Grasscutter.getLogger() .error( - "Deprecated field found in Banners config: " - + name - + " was replaced back in early May 2022, use " - + replacement - + " instead. You MUST remove this field from your config."); + "Deprecated field found in Banners config: {} was replaced back in early May 2022, use {} instead. You MUST remove this field from your config.", + name, + replacement); this.deprecated = true; } diff --git a/src/main/java/emu/grasscutter/game/gacha/GachaRecord.java b/src/main/java/emu/grasscutter/game/gacha/GachaRecord.java index b1bbc7172dd..779a1042444 100644 --- a/src/main/java/emu/grasscutter/game/gacha/GachaRecord.java +++ b/src/main/java/emu/grasscutter/game/gacha/GachaRecord.java @@ -2,8 +2,12 @@ import dev.morphia.annotations.*; import java.util.Date; +import lombok.Getter; +import lombok.Setter; import org.bson.types.ObjectId; +@Setter +@Getter @Entity(value = "gachas", useDiscriminator = false) public class GachaRecord { @Id private ObjectId id; @@ -23,46 +27,6 @@ public GachaRecord(int itemId, int ownerId, int gachaType) { this.gachaType = gachaType; } - public int getOwnerId() { - return ownerId; - } - - public void setOwnerId(int ownerId) { - this.ownerId = ownerId; - } - - public int getGachaType() { - return gachaType; - } - - public void setGachaType(int type) { - this.gachaType = type; - } - - public Date getTransactionDate() { - return transactionDate; - } - - public void setTransactionDate(Date transactionDate) { - this.transactionDate = transactionDate; - } - - public int getItemID() { - return itemID; - } - - public void setItemID(int itemID) { - this.itemID = itemID; - } - - public ObjectId getId() { - return id; - } - - public void setId(ObjectId id) { - this.id = id; - } - public String toString() { return toJsonString(); } diff --git a/src/main/java/emu/grasscutter/game/gacha/GachaSystem.java b/src/main/java/emu/grasscutter/game/gacha/GachaSystem.java index 649aa597275..2657d3c0235 100644 --- a/src/main/java/emu/grasscutter/game/gacha/GachaSystem.java +++ b/src/main/java/emu/grasscutter/game/gacha/GachaSystem.java @@ -26,12 +26,13 @@ import java.nio.file.*; import java.util.*; import java.util.concurrent.ThreadLocalRandom; +import lombok.Getter; import org.greenrobot.eventbus.Subscribe; public class GachaSystem extends BaseGameSystem { private static final int starglitterId = 221; private static final int stardustId = 222; - private final Int2ObjectMap gachaBanners; + @Getter private final Int2ObjectMap gachaBanners; private WatchService watchService; public GachaSystem(GameServer server) { @@ -41,10 +42,6 @@ public GachaSystem(GameServer server) { this.startWatcher(server); } - public Int2ObjectMap getGachaBanners() { - return gachaBanners; - } - public int randomRange(int min, int max) { // Both are inclusive return ThreadLocalRandom.current().nextInt(max - min + 1) + min; } @@ -105,7 +102,7 @@ private synchronized int drawRoulette(int[] weights, int cutoff) { } total += weight; } - int roll = ThreadLocalRandom.current().nextInt((total < cutoff) ? total : cutoff); + int roll = ThreadLocalRandom.current().nextInt(Math.min(total, cutoff)); int subTotal = 0; for (int i = 0; i < weights.length; i++) { subTotal += weights[i]; diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index 10d488aa277..faafe050d62 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -281,12 +281,11 @@ public List toAvatarTalkFinishInfoProto() { return this.finishedTalkIdMap.entrySet().stream() .map( - e -> { - return HomeAvatarTalkFinishInfo.newBuilder() - .setAvatarId(e.getKey()) - .addAllFinishTalkIdList(e.getValue()) - .build(); - }) + e -> + HomeAvatarTalkFinishInfo.newBuilder() + .setAvatarId(e.getKey()) + .addAllFinishTalkIdList(e.getValue()) + .build()) .toList(); } @@ -395,13 +394,7 @@ public void takeHomeFetter(Player player) { .get(player.getCurrentRealmId() + 2000) .getBlockItems() .forEach( - (i, e) -> { - e.getDeployNPCList() - .forEach( - id -> { - invitedAvatars.add(id.getAvatarId()); - }); - }); + (i, e) -> e.getDeployNPCList().forEach(id -> invitedAvatars.add(id.getAvatarId()))); // Check as realm 5 inside is not in defaults and will be null if (Objects.nonNull(mainHouseMap.get(player.getCurrentRealmId() + 2000))) { @@ -410,13 +403,7 @@ public void takeHomeFetter(Player player) { .get(player.getCurrentRealmId() + 2000) .getBlockItems() .forEach( - (i, e) -> { - e.getDeployNPCList() - .forEach( - id -> { - invitedAvatars.add(id.getAvatarId()); - }); - }); + (i, e) -> e.getDeployNPCList().forEach(id -> invitedAvatars.add(id.getAvatarId()))); } // Add exp to all avatars diff --git a/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java b/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java index 6d824d584a4..b7ac1d826d4 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java +++ b/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java @@ -93,26 +93,25 @@ private void fireAllAvatarRewardEvents() { .map(HomeBlockItem::getDeployNPCList) .flatMap(Collection::stream) .forEach( - avatar -> { - suites.forEach( - suite -> { - var data = - SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom( - avatar.getAvatarId(), suite.getSuiteId()); - if (data == null || this.home.isRewardEventFinished(data.getId())) { - return; - } - - this.rewardEvents.add( - new HomeAvatarRewardEvent( - homeOwner, - data.getId(), - data.getRewardID(), - data.getAvatarID(), - data.getSuiteId(), - suite.getGuid())); - }); - }); + avatar -> + suites.forEach( + suite -> { + var data = + SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom( + avatar.getAvatarId(), suite.getSuiteId()); + if (data == null || this.home.isRewardEventFinished(data.getId())) { + return; + } + + this.rewardEvents.add( + new HomeAvatarRewardEvent( + homeOwner, + data.getId(), + data.getRewardID(), + data.getAvatarID(), + data.getSuiteId(), + suite.getGuid())); + })); if (this.summonEvents != null) { var suiteIdList = this.rewardEvents.stream().map(HomeAvatarRewardEvent::getSuiteId).toList(); diff --git a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java index 111dba9cf4f..2953479f83f 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java @@ -103,13 +103,12 @@ public List getAnimals(Scene scene) { homeAnimalItem -> GameData.getHomeWorldAnimalDataMap().containsKey(homeAnimalItem.getFurnitureId())) .map( - homeAnimalItem -> { - return new EntityHomeAnimal( - scene, - GameData.getHomeWorldAnimalDataMap().get(homeAnimalItem.getFurnitureId()), - homeAnimalItem.getSpawnPos(), - homeAnimalItem.getSpawnRot()); - }) + homeAnimalItem -> + new EntityHomeAnimal( + scene, + GameData.getHomeWorldAnimalDataMap().get(homeAnimalItem.getFurnitureId()), + homeAnimalItem.getSpawnPos(), + homeAnimalItem.getSpawnRot())) .toList(); } diff --git a/src/main/java/emu/grasscutter/game/inventory/BagTab.java b/src/main/java/emu/grasscutter/game/inventory/BagTab.java index 697374b75fe..30fba692c67 100644 --- a/src/main/java/emu/grasscutter/game/inventory/BagTab.java +++ b/src/main/java/emu/grasscutter/game/inventory/BagTab.java @@ -5,6 +5,7 @@ import java.util.stream.Stream; import lombok.*; +@Getter @RequiredArgsConstructor public enum BagTab { TAB_NONE(0), @@ -30,7 +31,7 @@ public enum BagTab { }); } - @Getter private final int value; + private final int value; /** * Fetches the bag tab by its value. diff --git a/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java b/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java index 5da1ae1ca7b..22b79f13b6e 100644 --- a/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java +++ b/src/main/java/emu/grasscutter/game/inventory/EquipInventoryTab.java @@ -7,7 +7,7 @@ public class EquipInventoryTab implements InventoryTab { private final int maxCapacity; public EquipInventoryTab(int maxCapacity) { - this.items = new HashSet(); + this.items = new HashSet<>(); this.maxCapacity = maxCapacity; } diff --git a/src/main/java/emu/grasscutter/game/inventory/EquipType.java b/src/main/java/emu/grasscutter/game/inventory/EquipType.java index 00bf4e078dd..5efd255f12a 100644 --- a/src/main/java/emu/grasscutter/game/inventory/EquipType.java +++ b/src/main/java/emu/grasscutter/game/inventory/EquipType.java @@ -5,6 +5,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum EquipType { EQUIP_NONE(0), EQUIP_BRACER(1), @@ -26,7 +27,7 @@ public enum EquipType { }); } - @Getter private final int value; + private final int value; EquipType(int value) { this.value = value; diff --git a/src/main/java/emu/grasscutter/game/inventory/GameItem.java b/src/main/java/emu/grasscutter/game/inventory/GameItem.java index a89f9f30f09..558dd67002d 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GameItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GameItem.java @@ -28,7 +28,7 @@ @Entity(value = "items", useDiscriminator = false) public class GameItem { @Id private ObjectId id; - @Indexed private int ownerId; + @Getter @Indexed private int ownerId; @Getter @Setter private int itemId; @Getter @Setter private int count; @@ -112,10 +112,6 @@ public GameItem(ItemData data, int count) { } } - public int getOwnerId() { - return ownerId; - } - public void setOwner(Player player) { this.ownerId = player.getUid(); this.guid = player.getNextGameGuid(); @@ -277,9 +273,9 @@ public SceneWeaponInfo createSceneWeaponInfo() { .setGuid(this.getGuid()) .setLevel(this.getLevel()) .setGadgetId(this.getItemData().getGadgetId()) - .setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0)); + .setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(!getAffixes().isEmpty())); - if (this.getAffixes() != null && this.getAffixes().size() > 0) { + if (this.getAffixes() != null && !this.getAffixes().isEmpty()) { for (int affix : this.getAffixes()) { weaponInfo.putAffixMap(affix, this.getRefinement()); } @@ -306,7 +302,7 @@ public Weapon toWeaponProto() { .setExp(this.getExp()) .setPromoteLevel(this.getPromoteLevel()); - if (this.getAffixes() != null && this.getAffixes().size() > 0) { + if (this.getAffixes() != null && !this.getAffixes().isEmpty()) { for (int affix : this.getAffixes()) { weapon.putAffixMap(affix, this.getRefinement()); } diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index 7967617c136..605be0f6744 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -7,24 +7,35 @@ import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.avatar.*; -import emu.grasscutter.game.player.*; -import emu.grasscutter.game.props.*; +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.avatar.AvatarStorage; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.player.BasePlayerManager; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ItemUseAction.UseItemParams; +import emu.grasscutter.game.props.PlayerProperty; +import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; import emu.grasscutter.server.event.player.PlayerObtainItemEvent; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Utils; -import it.unimi.dsi.fastutil.ints.*; -import it.unimi.dsi.fastutil.longs.*; -import java.util.*; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; import javax.annotation.Nullable; +import lombok.Getter; import lombok.val; public class Inventory extends BasePlayerManager implements Iterable { private final Long2ObjectMap store; - private final Int2ObjectMap inventoryTypes; + @Getter private final Int2ObjectMap inventoryTypes; public Inventory(Player player) { super(player); @@ -49,10 +60,6 @@ public Long2ObjectMap getItems() { return store; } - public Int2ObjectMap getInventoryTypes() { - return inventoryTypes; - } - public InventoryTab getInventoryTab(ItemType type) { return getInventoryTypes().get(type.getValue()); } @@ -178,7 +185,7 @@ public void addItems(Collection items, ActionReason reason) { changedItems.add(result); } } - if (changedItems.size() == 0) { + if (changedItems.isEmpty()) { return; } if (reason != null) { @@ -322,9 +329,8 @@ private synchronized GameItem putItem(GameItem item) { case MATERIAL_NAMECARD: Grasscutter.getLogger() .warn( - "Attempted to add a " - + item.getItemData().getMaterialType().name() - + " to inventory, but item definition lacks isUseOnGain. This indicates a Resources error."); + "Attempted to add a {} to inventory, but item definition lacks isUseOnGain. This indicates a Resources error.", + item.getItemData().getMaterialType().name()); return null; default: if (tab == null) { @@ -370,7 +376,7 @@ private void addVirtualItem(int itemId, int count) { switch (itemId) { case 101 -> // Character exp this.player.getTeamManager().getActiveTeam().stream() - .map(e -> e.getAvatar()) + .map(EntityAvatar::getAvatar) .forEach( avatar -> this.player @@ -381,7 +387,7 @@ private void addVirtualItem(int itemId, int count) { this.player.addExpDirectly(count); case 105 -> // Companionship exp this.player.getTeamManager().getActiveTeam().stream() - .map(e -> e.getAvatar()) + .map(EntityAvatar::getAvatar) .forEach( avatar -> this.player @@ -430,26 +436,29 @@ private GameItem payVirtualItem(int itemId, int count) { } private int getVirtualItemCount(int itemId) { - switch (itemId) { - case 201: // Primogem - return this.player.getPrimogems(); - case 202: // Mora - return this.player.getMora(); - case 203: // Genesis Crystals - return this.player.getCrystals(); - case 106: // Resin - return this.player.getProperty(PlayerProperty.PROP_PLAYER_RESIN); - case 107: // Legendary Key - return this.player.getProperty(PlayerProperty.PROP_PLAYER_LEGENDARY_KEY); - case 204: // Home Coin - return this.player.getHomeCoin(); - default: + return switch (itemId) { + case 201 -> // Primogem + this.player.getPrimogems(); + case 202 -> // Mora + this.player.getMora(); + case 203 -> // Genesis Crystals + this.player.getCrystals(); + case 106 -> // Resin + this.player.getProperty(PlayerProperty.PROP_PLAYER_RESIN); + case 107 -> // Legendary Key + this.player.getProperty(PlayerProperty.PROP_PLAYER_LEGENDARY_KEY); + case 204 -> // Home Coin + this.player.getHomeCoin(); + default -> { GameItem item = getInventoryTab(ItemType.ITEM_MATERIAL) .getItemById( - itemId); // What if we ever want to operate on weapons/relics/furniture? :S - return (item == null) ? 0 : item.getCount(); - } + itemId); // What if we ever want to operate on weapons/relics/furniture? :Syield + // (item == null) ? 0 : item.getCount(); // What if we ever want to + // operate on weapons/relics/furniture? :S + yield (item == null) ? 0 : item.getCount(); + } + }; } public synchronized boolean payItem(int id, int count) { diff --git a/src/main/java/emu/grasscutter/game/inventory/ItemDef.java b/src/main/java/emu/grasscutter/game/inventory/ItemDef.java index 0dde8fd053b..b0b4987f54b 100644 --- a/src/main/java/emu/grasscutter/game/inventory/ItemDef.java +++ b/src/main/java/emu/grasscutter/game/inventory/ItemDef.java @@ -1,5 +1,10 @@ package emu.grasscutter.game.inventory; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter public class ItemDef { private int itemId; private int count; @@ -8,20 +13,4 @@ public ItemDef(int itemId, int count) { this.itemId = itemId; this.count = count; } - - public int getItemId() { - return itemId; - } - - public void setItemId(int itemId) { - this.itemId = itemId; - } - - public int getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } } diff --git a/src/main/java/emu/grasscutter/game/inventory/ItemQuality.java b/src/main/java/emu/grasscutter/game/inventory/ItemQuality.java index 954230d622b..6595277610b 100644 --- a/src/main/java/emu/grasscutter/game/inventory/ItemQuality.java +++ b/src/main/java/emu/grasscutter/game/inventory/ItemQuality.java @@ -5,6 +5,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum ItemQuality { QUALITY_NONE(0), QUALITY_WHITE(1), @@ -26,7 +27,7 @@ public enum ItemQuality { }); } - @Getter private final int value; + private final int value; ItemQuality(int value) { this.value = value; diff --git a/src/main/java/emu/grasscutter/game/inventory/ItemType.java b/src/main/java/emu/grasscutter/game/inventory/ItemType.java index c6ab80e3350..237d2231809 100644 --- a/src/main/java/emu/grasscutter/game/inventory/ItemType.java +++ b/src/main/java/emu/grasscutter/game/inventory/ItemType.java @@ -5,6 +5,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum ItemType { ITEM_NONE(0), ITEM_VIRTUAL(1), @@ -26,7 +27,7 @@ public enum ItemType { }); } - @Getter private final int value; + private final int value; ItemType(int value) { this.value = value; diff --git a/src/main/java/emu/grasscutter/game/inventory/MaterialType.java b/src/main/java/emu/grasscutter/game/inventory/MaterialType.java index e53764744e2..ba34eb632fc 100644 --- a/src/main/java/emu/grasscutter/game/inventory/MaterialType.java +++ b/src/main/java/emu/grasscutter/game/inventory/MaterialType.java @@ -5,6 +5,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum MaterialType { MATERIAL_NONE(0), MATERIAL_FOOD(1), @@ -60,7 +61,7 @@ public enum MaterialType { }); } - @Getter private final int value; + private final int value; MaterialType(int value) { this.value = value; diff --git a/src/main/java/emu/grasscutter/game/mail/Mail.java b/src/main/java/emu/grasscutter/game/mail/Mail.java index 89161b95007..b1276f1ba07 100644 --- a/src/main/java/emu/grasscutter/game/mail/Mail.java +++ b/src/main/java/emu/grasscutter/game/mail/Mail.java @@ -11,26 +11,28 @@ import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent; import java.time.Instant; import java.util.*; +import lombok.Getter; +import lombok.Setter; import org.bson.types.ObjectId; @Entity(value = "mail", useDiscriminator = false) public final class Mail { - @Id private ObjectId id; - @Indexed private int ownerUid; - public MailContent mailContent; - public List itemList; - public long sendTime; + @Getter @Id private ObjectId id; + @Setter @Getter @Indexed private int ownerUid; + public final MailContent mailContent; + public final List itemList; + public final long sendTime; public long expireTime; public int importance; public boolean isRead; public boolean isAttachmentGot; - public int stateValue; + public final int stateValue; @Transient private boolean shouldDelete; public Mail() { this( new MailContent(), - new ArrayList(), + new ArrayList<>(), (int) Instant.now().getEpochSecond() + 604800); // TODO: add expire time to send mail command } @@ -59,18 +61,6 @@ public Mail( this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box. } - public ObjectId getId() { - return id; - } - - public int getOwnerUid() { - return ownerUid; - } - - public void setOwnerUid(int ownerUid) { - this.ownerUid = ownerUid; - } - public MailDataOuterClass.MailData toProto(Player player) { return MailDataOuterClass.MailData.newBuilder() .setMailId(player.getMailId(this)) @@ -122,9 +112,9 @@ public MailTextContent toProto() { @Entity public static class MailItem { - public int itemId; - public int itemCount; - public int itemLevel; + public final int itemId; + public final int itemCount; + public final int itemLevel; public MailItem() { this.itemId = 11101; diff --git a/src/main/java/emu/grasscutter/game/mail/MailHandler.java b/src/main/java/emu/grasscutter/game/mail/MailHandler.java index 51ca53698f5..b6e38fb3a4c 100644 --- a/src/main/java/emu/grasscutter/game/mail/MailHandler.java +++ b/src/main/java/emu/grasscutter/game/mail/MailHandler.java @@ -6,7 +6,9 @@ import emu.grasscutter.server.event.player.PlayerReceiveMailEvent; import emu.grasscutter.server.packet.send.*; import java.util.*; +import lombok.Getter; +@Getter public class MailHandler extends BasePlayerManager { private final List mail; @@ -16,10 +18,6 @@ public MailHandler(Player player) { this.mail = new ArrayList<>(); } - public List getMail() { - return mail; - } - // ---------------------MAIL------------------------ public void sendMail(Mail message) { @@ -36,11 +34,9 @@ public void sendMail(Mail message) { Grasscutter.getLogger() .debug( - "Mail sent to user [" - + this.getPlayer().getUid() - + ":" - + this.getPlayer().getNickname() - + "]!"); + "Mail sent to user [{}:{}]!", + this.getPlayer().getUid(), + this.getPlayer().getNickname()); if (this.getPlayer().isOnline()) { this.getPlayer().sendPacket(new PacketMailChangeNotify(this.getPlayer(), message)); @@ -63,9 +59,8 @@ public boolean deleteMail(int mailId) { } public void deleteMail(List mailList) { - List sortedMailList = new ArrayList<>(); - sortedMailList.addAll(mailList); - Collections.sort(sortedMailList, Collections.reverseOrder()); + List sortedMailList = new ArrayList<>(mailList); + sortedMailList.sort(Collections.reverseOrder()); List deleted = new ArrayList<>(); diff --git a/src/main/java/emu/grasscutter/game/managers/SatiationManager.java b/src/main/java/emu/grasscutter/game/managers/SatiationManager.java index 29e99286397..71d1fea2115 100644 --- a/src/main/java/emu/grasscutter/game/managers/SatiationManager.java +++ b/src/main/java/emu/grasscutter/game/managers/SatiationManager.java @@ -98,7 +98,7 @@ public synchronized void reduceSatiation() { * Player Updates ********************/ public synchronized void updateSingleAvatar(Avatar avatar, float givenTime) { - float time = (player.getClientTime() / 1000) + givenTime; + float time = ((float) player.getClientTime() / 1000) + givenTime; player.getSession().send(new PacketAvatarPropNotify(avatar)); player.getSession().send(new PacketAvatarSatiationDataNotify(time, avatar)); } diff --git a/src/main/java/emu/grasscutter/game/managers/SotSManager.java b/src/main/java/emu/grasscutter/game/managers/SotSManager.java index 6427de18569..d3f5d043046 100644 --- a/src/main/java/emu/grasscutter/game/managers/SotSManager.java +++ b/src/main/java/emu/grasscutter/game/managers/SotSManager.java @@ -104,7 +104,7 @@ public void autoRevive() { if (isAlive) { return; } - logger.trace("Reviving avatar " + entity.getAvatar().getAvatarData().getName()); + logger.trace("Reviving avatar {}", entity.getAvatar().getAvatarData().getName()); player.getTeamManager().reviveAvatar(entity.getAvatar()); player.getTeamManager().healAvatar(entity.getAvatar(), 30, 0); }); @@ -130,8 +130,7 @@ public void checkAndHealAvatar(EntityAvatar entity) { setCurrentVolume(0); } if (needHP > 0) { - logger.trace( - "Healing avatar " + entity.getAvatar().getAvatarData().getName() + " +" + needHP); + logger.trace("Healing avatar {} +{}", entity.getAvatar().getAvatarData().getName(), needHP); player.getTeamManager().healAvatar(entity.getAvatar(), 0, needHP); player .getSession() @@ -168,9 +167,9 @@ public void refillSpringVolume() { int secondsSinceLastUsed = (int) (now - getLastUsed()); // 15s = 1% max volume int volumeRefilled = secondsSinceLastUsed * maxVolume / 15 / 100; - logger.trace("Statue has refilled HP volume: " + volumeRefilled); + logger.trace("Statue has refilled HP volume: {}", volumeRefilled); currentVolume = Math.min(currentVolume + volumeRefilled, maxVolume); - logger.trace("Statue remaining HP volume: " + currentVolume); + logger.trace("Statue remaining HP volume: {}", currentVolume); setCurrentVolume(currentVolume); } } @@ -182,10 +181,9 @@ public void run() { refillSpringVolume(); logger.trace( - "isAutoRecoveryEnabled: " - + getIsAutoRecoveryEnabled() - + "\tautoRecoverPercentage: " - + getAutoRecoveryPercentage()); + "isAutoRecoveryEnabled: {}\tautoRecoverPercentage: {}", + getIsAutoRecoveryEnabled(), + getAutoRecoveryPercentage()); if (getIsAutoRecoveryEnabled()) { List activeTeam = player.getTeamManager().getActiveTeam(); @@ -218,11 +216,7 @@ public CityData getCityByAreaId(int areaId) { public CityInfoData getCityInfo(int cityId) { if (player.getCityInfoData() == null) player.setCityInfoData(new HashMap<>()); - var cityInfo = player.getCityInfoData().get(cityId); - if (cityInfo == null) { - cityInfo = new CityInfoData(cityId); - player.getCityInfoData().put(cityId, cityInfo); - } + var cityInfo = player.getCityInfoData().computeIfAbsent(cityId, CityInfoData::new); return cityInfo; } 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 d73778cca78..7ff36ac7afd 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomActivity.java @@ -9,12 +9,13 @@ import emu.grasscutter.scripts.data.*; import emu.grasscutter.utils.Utils; import java.util.*; +import lombok.Getter; public final class BlossomActivity { private final SceneGroup tempSceneGroup; - private final WorldChallenge challenge; - private final EntityGadget gadget; + @Getter private final WorldChallenge challenge; + @Getter private final EntityGadget gadget; private EntityGadget chest; private int step; private final int goal; @@ -49,10 +50,6 @@ public BlossomActivity( // this.challengeTriggers.add(new InTimeTrigger()); } - public WorldChallenge getChallenge() { - return this.challenge; - } - public void setMonsters(List monsters) { this.activeMonsters.clear(); this.activeMonsters.addAll(monsters); @@ -119,10 +116,6 @@ public void onTick() { } } - public EntityGadget getGadget() { - return gadget; - } - public EntityGadget getChest() { if (chest == null) { EntityGadget rewardGadget = diff --git a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomConfig.java b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomConfig.java index a8652e8fe74..f151aad4887 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomConfig.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomConfig.java @@ -3,9 +3,10 @@ import java.util.*; import lombok.Getter; +@Getter public class BlossomConfig { - @Getter private int monsterFightingVolume; + private int monsterFightingVolume; // @Getter private Int2ObjectMap monsterIdsPerDifficulty; // Need to wrangle Gson for // this - @Getter private Map> monsterIdsPerDifficulty; + private Map> monsterIdsPerDifficulty; } diff --git a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomManager.java b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomManager.java index 5322c22c972..9644553cd64 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomManager.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomManager.java @@ -101,7 +101,7 @@ public void initBlossom(EntityGadget gadget) { } } - Grasscutter.getLogger().info("Blossom Monsters:" + monsters); + Grasscutter.getLogger().info("Blossom Monsters:{}", monsters); activity = new BlossomActivity(entityGadget, monsters, -1, worldLevel); blossomActivities.add(activity); @@ -118,7 +118,7 @@ public void initBlossom(EntityGadget gadget) { public void notifyIcon() { final int wl = getWorldLevel(); - final int worldLevel = (wl < 0) ? 0 : ((wl > 8) ? 8 : wl); + final int worldLevel = (wl < 0) ? 0 : (Math.min(wl, 8)); final var worldLevelData = GameData.getWorldLevelDataMap().get(worldLevel); final int monsterLevel = (worldLevelData != null) ? worldLevelData.getMonsterLevel() : 1; List blossoms = new ArrayList<>(); @@ -203,7 +203,7 @@ public List onReward(Player player, EntityGadget chest, boolean useCon RewardPreviewData blossomRewards = getRewardList(type, worldLevel); if (blossomRewards == null) { Grasscutter.getLogger() - .error("Blossom could not support world level : " + worldLevel); + .error("Blossom could not support world level : {}", worldLevel); return null; } var rewards = blossomRewards.getPreviewItems(); diff --git a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java index 925e05b0d59..b8707434691 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java @@ -5,16 +5,17 @@ import java.util.stream.*; import lombok.Getter; +@Getter public enum BlossomType { GOLD(70360056, 101001001, 1), BLUE(70360057, 101002003, 2); private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>( - Stream.of(values()).collect(Collectors.toMap(x -> x.getGadgetId(), x -> x))); - @Getter private final int gadgetId; - @Getter private final int circleCampId; - @Getter private final int blossomChestId; + Stream.of(values()).collect(Collectors.toMap(BlossomType::getGadgetId, x -> x))); + private final int gadgetId; + private final int circleCampId; + private final int blossomChestId; BlossomType(int gadgetId, int circleCampId, int blossomChestId) { this.gadgetId = gadgetId; diff --git a/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java b/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java index 0f1b1453fb3..b24eadbfc50 100644 --- a/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java +++ b/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java @@ -4,7 +4,8 @@ import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.CompoundData; import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.*; +import emu.grasscutter.game.player.BasePlayerManager; +import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; import emu.grasscutter.net.proto.GetCompoundDataReqOuterClass.GetCompoundDataReq; @@ -12,7 +13,10 @@ import emu.grasscutter.net.proto.PlayerCompoundMaterialReqOuterClass.PlayerCompoundMaterialReq; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.TakeCompoundOutputReqOuterClass.TakeCompoundOutputReq; -import emu.grasscutter.server.packet.send.*; +import emu.grasscutter.server.packet.send.PackageTakeCompoundOutputRsp; +import emu.grasscutter.server.packet.send.PacketCompoundDataNotify; +import emu.grasscutter.server.packet.send.PacketGetCompoundDataRsp; +import emu.grasscutter.server.packet.send.PacketPlayerCompoundMaterialRsp; import emu.grasscutter.utils.Utils; import java.util.*; diff --git a/src/main/java/emu/grasscutter/game/managers/deforestation/HitTreeRecord.java b/src/main/java/emu/grasscutter/game/managers/deforestation/HitTreeRecord.java index f29467eaeeb..ebda78540e1 100644 --- a/src/main/java/emu/grasscutter/game/managers/deforestation/HitTreeRecord.java +++ b/src/main/java/emu/grasscutter/game/managers/deforestation/HitTreeRecord.java @@ -1,7 +1,11 @@ package emu.grasscutter.game.managers.deforestation; +import lombok.Getter; + public class HitTreeRecord { - private final int unique; + /** -- GETTER -- get unique id */ + @Getter private final int unique; + private short count; // hit this tree times private long time; // last available hitting time @@ -36,11 +40,6 @@ public boolean record() { } } - /** get unique id */ - public int getUnique() { - return unique; - } - @Override public String toString() { return "HitTreeRecord{" + "unique=" + unique + ", count=" + count + ", time=" + time + '}'; diff --git a/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropEntry.java b/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropEntry.java index 6832294a016..451b2d8cea8 100644 --- a/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropEntry.java +++ b/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropEntry.java @@ -1,16 +1,10 @@ package emu.grasscutter.game.managers.energy; import java.util.List; +import lombok.Getter; +@Getter public class EnergyDropEntry { private int dropId; private List dropList; - - public int getDropId() { - return this.dropId; - } - - public List getDropList() { - return this.dropList; - } } diff --git a/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropInfo.java b/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropInfo.java index 2ba4d584277..420400b437f 100644 --- a/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropInfo.java +++ b/src/main/java/emu/grasscutter/game/managers/energy/EnergyDropInfo.java @@ -1,14 +1,9 @@ package emu.grasscutter.game.managers.energy; +import lombok.Getter; + +@Getter public class EnergyDropInfo { private int ballId; private int count; - - public int getBallId() { - return this.ballId; - } - - public int getCount() { - return this.count; - } } diff --git a/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java b/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java index 8be641b19c4..dd177d6dba5 100644 --- a/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java +++ b/src/main/java/emu/grasscutter/game/managers/energy/EnergyManager.java @@ -45,10 +45,7 @@ public static void initialize() { // Read the data we need for monster energy drops. try { DataLoader.loadList("EnergyDrop.json", EnergyDropEntry.class) - .forEach( - entry -> { - energyDropData.put(entry.getDropId(), entry.getDropList()); - }); + .forEach(entry -> energyDropData.put(entry.getDropId(), entry.getDropList())); Grasscutter.getLogger().debug("Energy drop data successfully loaded."); } catch (Exception ex) { @@ -59,9 +56,7 @@ public static void initialize() { try { DataLoader.loadList("SkillParticleGeneration.json", SkillParticleGenerationEntry.class) .forEach( - entry -> { - skillParticleGenerationData.put(entry.getAvatarId(), entry.getAmountList()); - }); + entry -> skillParticleGenerationData.put(entry.getAvatarId(), entry.getAmountList())); Grasscutter.getLogger().debug("Skill particle generation data successfully loaded."); } catch (Exception ex) { diff --git a/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationEntry.java b/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationEntry.java index b7047a93098..2642fd66509 100644 --- a/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationEntry.java +++ b/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationEntry.java @@ -1,16 +1,10 @@ package emu.grasscutter.game.managers.energy; import java.util.List; +import lombok.Getter; +@Getter public class SkillParticleGenerationEntry { private int avatarId; private List amountList; - - public int getAvatarId() { - return this.avatarId; - } - - public List getAmountList() { - return this.amountList; - } } diff --git a/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationInfo.java b/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationInfo.java index c9ce4067ad6..115e5d0185a 100644 --- a/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationInfo.java +++ b/src/main/java/emu/grasscutter/game/managers/energy/SkillParticleGenerationInfo.java @@ -1,14 +1,9 @@ package emu.grasscutter.game.managers.energy; +import lombok.Getter; + +@Getter public class SkillParticleGenerationInfo { private int value; private int chance; - - public int getValue() { - return this.value; - } - - public int getChance() { - return this.chance; - } } diff --git a/src/main/java/emu/grasscutter/game/managers/forging/ActiveForgeData.java b/src/main/java/emu/grasscutter/game/managers/forging/ActiveForgeData.java index fd240864507..f6854a2b993 100644 --- a/src/main/java/emu/grasscutter/game/managers/forging/ActiveForgeData.java +++ b/src/main/java/emu/grasscutter/game/managers/forging/ActiveForgeData.java @@ -1,18 +1,20 @@ package emu.grasscutter.game.managers.forging; import dev.morphia.annotations.Entity; +import lombok.Getter; +import lombok.Setter; @Entity public class ActiveForgeData { - private int forgeId; - private int avatarId; - private int count; + @Setter @Getter private int forgeId; + @Setter @Getter private int avatarId; + @Setter @Getter private int count; - private int startTime; - private int forgeTime; + @Setter @Getter private int startTime; + @Setter @Getter private int forgeTime; private int lastUnfinishedCount; - private boolean changed; + @Setter @Getter private boolean changed; public int getFinishedCount(int currentTime) { int timeDelta = currentTime - this.startTime; @@ -35,54 +37,6 @@ public int getTotalFinishTimestamp() { return this.startTime + this.forgeTime * this.count; } - public int getForgeId() { - return this.forgeId; - } - - public void setForgeId(int value) { - this.forgeId = value; - } - - public int getAvatarId() { - return this.avatarId; - } - - public void setAvatarId(int value) { - this.avatarId = value; - } - - public int getCount() { - return count; - } - - public void setCount(int value) { - this.count = value; - } - - public int getStartTime() { - return this.startTime; - } - - public void setStartTime(int value) { - this.startTime = value; - } - - public int getForgeTime() { - return this.forgeTime; - } - - public void setForgeTime(int value) { - this.forgeTime = value; - } - - public boolean isChanged() { - return this.changed; - } - - public void setChanged(boolean value) { - this.changed = value; - } - public boolean updateChanged(int currentTime) { int currentUnfinished = this.getUnfinishedCount(currentTime); diff --git a/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java b/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java index deca11dda8f..07a9685a6a3 100644 --- a/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java @@ -299,7 +299,7 @@ public synchronized void sendPlayerForgingUpdate() { // Determine if sending an update is necessary. // We only send an update if there are forges in the forge queue // that have changed since the last notification. - if (this.player.getActiveForges().size() <= 0) { + if (this.player.getActiveForges().size() == 0) { return; } @@ -314,6 +314,6 @@ public synchronized void sendPlayerForgingUpdate() { this.sendForgeQueueDataNotify(); // Reset changed flags. - this.player.getActiveForges().stream().forEach(forge -> forge.setChanged(false)); + this.player.getActiveForges().forEach(forge -> forge.setChanged(false)); } } diff --git a/src/main/java/emu/grasscutter/game/managers/mapmark/MapMark.java b/src/main/java/emu/grasscutter/game/managers/mapmark/MapMark.java index 930737bda5e..9253a6cda82 100644 --- a/src/main/java/emu/grasscutter/game/managers/mapmark/MapMark.java +++ b/src/main/java/emu/grasscutter/game/managers/mapmark/MapMark.java @@ -5,15 +5,17 @@ import emu.grasscutter.net.proto.MapMarkFromTypeOuterClass.MapMarkFromType; import emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint; import emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType; +import lombok.Getter; +@Getter @Entity public class MapMark { private int sceneId; private String name; private Position position; - private MapMarkPointType mapMarkPointType; + private final MapMarkPointType mapMarkPointType; private int monsterId; - private MapMarkFromType mapMarkFromType; + private final MapMarkFromType mapMarkFromType; private int questId; @Deprecated // Morhpia @@ -31,32 +33,4 @@ public MapMark(MapMarkPoint mapMarkPoint) { this.mapMarkFromType = mapMarkPoint.getFromType(); this.questId = mapMarkPoint.getQuestId(); } - - public int getSceneId() { - return this.sceneId; - } - - public String getName() { - return this.name; - } - - public Position getPosition() { - return this.position; - } - - public MapMarkPointType getMapMarkPointType() { - return this.mapMarkPointType; - } - - public int getMonsterId() { - return this.monsterId; - } - - public MapMarkFromType getMapMarkFromType() { - return this.mapMarkFromType; - } - - public int getQuestId() { - return this.questId; - } } diff --git a/src/main/java/emu/grasscutter/game/managers/stamina/BeforeUpdateStaminaListener.java b/src/main/java/emu/grasscutter/game/managers/stamina/BeforeUpdateStaminaListener.java index 725ec188014..967d20e0133 100644 --- a/src/main/java/emu/grasscutter/game/managers/stamina/BeforeUpdateStaminaListener.java +++ b/src/main/java/emu/grasscutter/game/managers/stamina/BeforeUpdateStaminaListener.java @@ -7,7 +7,7 @@ public interface BeforeUpdateStaminaListener { * * @param reason Why updating stamina. * @param newStamina New ABSOLUTE stamina value. - * @return true if you want to cancel this update, otherwise false. + * @return current stamina value. If you want to cancel this update, return the newStamina value. */ int onBeforeUpdateStamina(String reason, int newStamina, boolean isCharacterStamina); @@ -17,7 +17,7 @@ public interface BeforeUpdateStaminaListener { * * @param reason Why updating stamina. * @param consumption ConsumptionType and RELATIVE stamina change amount. - * @return true if you want to cancel this update, otherwise false. + * @return current stamina value. If you want to cancel this update, return the newStamina value. */ Consumption onBeforeUpdateStamina( String reason, Consumption consumption, boolean isCharacterStamina); diff --git a/src/main/java/emu/grasscutter/game/managers/stamina/StaminaManager.java b/src/main/java/emu/grasscutter/game/managers/stamina/StaminaManager.java index 8a0a86b1095..037aab174ae 100644 --- a/src/main/java/emu/grasscutter/game/managers/stamina/StaminaManager.java +++ b/src/main/java/emu/grasscutter/game/managers/stamina/StaminaManager.java @@ -229,8 +229,7 @@ private boolean isPlayerMoving() { float diffX = currentCoordinates.getX() - previousCoordinates.getX(); float diffY = currentCoordinates.getY() - previousCoordinates.getY(); float diffZ = currentCoordinates.getZ() - previousCoordinates.getZ(); - logger.trace("isPlayerMoving: " + previousCoordinates + ", " + currentCoordinates + - ", " + diffX + ", " + diffY + ", " + diffZ); + logger.trace("isPlayerMoving: {}, {}, {}, {}, {}", previousCoordinates, currentCoordinates, diffX, diffY, diffZ); return Math.abs(diffX) > 0.3 || Math.abs(diffY) > 0.2 || Math.abs(diffZ) > 0.3; } @@ -244,17 +243,13 @@ public int updateStaminaRelative(GameSession session, Consumption consumption, b for (Map.Entry listener : beforeUpdateStaminaListeners.entrySet()) { Consumption overriddenConsumption = listener.getValue().onBeforeUpdateStamina(consumption.type.toString(), consumption, isCharacterStamina); if ((overriddenConsumption.type != consumption.type) && (overriddenConsumption.amount != consumption.amount)) { - logger.debug("Stamina update relative(" + - consumption.type.toString() + ", " + consumption.amount + ") overridden to relative(" + - consumption.type.toString() + ", " + consumption.amount + ") by: " + listener.getKey()); + logger.debug("Stamina update relative({}, {}) overridden to relative({}, {}) by: {}", consumption.type.toString(), consumption.amount, consumption.type.toString(), consumption.amount, listener.getKey()); return currentStamina; } } int maxStamina = isCharacterStamina ? getMaxCharacterStamina() : getMaxVehicleStamina(); - logger.trace((isCharacterStamina ? "C " : "V ") + currentStamina + "/" + maxStamina + "\t" + currentState + "\t" + - (isPlayerMoving() ? "moving" : " ") + "\t(" + consumption.type + "," + - consumption.amount + ")"); + logger.trace("{}{}/{}\t{}\t{}\t({},{})", isCharacterStamina ? "C " : "V ", currentStamina, maxStamina, currentState, isPlayerMoving() ? "moving" : " ", consumption.type, consumption.amount); int newStamina = currentStamina + consumption.amount; if (newStamina < 0) { @@ -272,9 +267,7 @@ public int updateStaminaAbsolute(GameSession session, String reason, int newStam for (Map.Entry listener : beforeUpdateStaminaListeners.entrySet()) { int overriddenNewStamina = listener.getValue().onBeforeUpdateStamina(reason, newStamina, isCharacterStamina); if (overriddenNewStamina != newStamina) { - logger.debug("Stamina update absolute(" + - reason + ", " + newStamina + ") overridden to absolute(" + - reason + ", " + newStamina + ") by: " + listener.getKey()); + logger.debug("Stamina update absolute({}, {}) overridden to absolute({}, {}) by: {}", reason, newStamina, reason, newStamina, listener.getKey()); return currentStamina; } } @@ -450,8 +443,7 @@ public void run() { int currentVehicleStamina = getCurrentVehicleStamina(); int maxVehicleStamina = getMaxVehicleStamina(); if (moving || (currentCharacterStamina < maxCharacterStamina) || (currentVehicleStamina < maxVehicleStamina)) { - logger.trace("Player moving: " + moving + ", stamina full: " + - (currentCharacterStamina >= maxCharacterStamina) + ", recalculate stamina"); + logger.trace("Player moving: {}, stamina full: {}, recalculate stamina", moving, currentCharacterStamina >= maxCharacterStamina); boolean isCharacterStamina = true; Consumption consumption; @@ -483,7 +475,7 @@ public void run() { if (consumption.amount < 0 && isCharacterStamina) { // Do not apply reduction factor when recovering stamina if (player.getTeamManager().getTeamResonances().contains(10301)) { - consumption.amount *= 0.85f; + consumption.amount *= (int) 0.85f; } } // Delay 1 seconds before starts recovering stamina @@ -499,7 +491,7 @@ public void run() { // For others recover after 1 seconds (5 ticks) - as official server does. staminaRecoverDelay++; consumption.amount = 0; - logger.trace("Delaying recovery: " + staminaRecoverDelay); + logger.trace("Delaying recovery: {}", staminaRecoverDelay); } } updateStaminaRelative(cachedSession, consumption, isCharacterStamina); @@ -514,8 +506,7 @@ private void handleDrowning() { // TODO: fix drowning waverider entity int stamina = getCurrentCharacterStamina(); if (stamina < 10) { - logger.trace(getCurrentCharacterStamina() + "/" + - getMaxCharacterStamina() + "\t" + currentState); + logger.trace("{}/{}\t{}", getCurrentCharacterStamina(), getMaxCharacterStamina(), currentState); if (currentState != MotionState.MOTION_STATE_SWIM_IDLE) { killAvatar(cachedSession, cachedEntity, PlayerDieType.PLAYER_DIE_TYPE_DRAWN); } @@ -552,8 +543,8 @@ private Consumption getClimbConsumption() { consumption.amount = ConsumptionType.CLIMBING.amount; } // Climbing specific reductions - consumption.amount *= getFoodCostReductionFactor(ClimbFoodReductionMap); - consumption.amount *= getTalentCostReductionFactor(ClimbTalentReductionMap); + consumption.amount *= (int) getFoodCostReductionFactor(ClimbFoodReductionMap); + consumption.amount *= (int) getTalentCostReductionFactor(ClimbTalentReductionMap); return consumption; } @@ -569,8 +560,8 @@ private Consumption getSwimConsumptions() { consumption.amount = ConsumptionType.SWIM_DASH.amount; } // Swimming specific reductions - consumption.amount *= getFoodCostReductionFactor(SwimFoodReductionMap); - consumption.amount *= getTalentCostReductionFactor(SwimTalentReductionMap); + consumption.amount *= (int) getFoodCostReductionFactor(SwimFoodReductionMap); + consumption.amount *= (int) getTalentCostReductionFactor(SwimTalentReductionMap); return consumption; } @@ -580,7 +571,7 @@ private Consumption getDashConsumption() { consumption.type = ConsumptionType.DASH; consumption.amount = ConsumptionType.DASH.amount; // Dashing specific reductions - consumption.amount *= getFoodCostReductionFactor(DashFoodReductionMap); + consumption.amount *= (int) getFoodCostReductionFactor(DashFoodReductionMap); } return consumption; } @@ -592,8 +583,8 @@ private Consumption getFlyConsumption() { } Consumption consumption = new Consumption(ConsumptionType.FLY); // Flying specific reductions - consumption.amount *= getFoodCostReductionFactor(FlyFoodReductionMap); - consumption.amount *= getTalentCostReductionFactor(FlyTalentReductionMap); + consumption.amount *= (int) getFoodCostReductionFactor(FlyFoodReductionMap); + consumption.amount *= (int) getTalentCostReductionFactor(FlyTalentReductionMap); return consumption; } diff --git a/src/main/java/emu/grasscutter/game/player/BasePlayerDataManager.java b/src/main/java/emu/grasscutter/game/player/BasePlayerDataManager.java index a8f70bfb41b..8e29adee67c 100644 --- a/src/main/java/emu/grasscutter/game/player/BasePlayerDataManager.java +++ b/src/main/java/emu/grasscutter/game/player/BasePlayerDataManager.java @@ -1,7 +1,9 @@ package emu.grasscutter.game.player; +import lombok.Getter; import lombok.NonNull; +@Getter public abstract class BasePlayerDataManager { protected transient Player player; @@ -11,10 +13,6 @@ public BasePlayerDataManager(@NonNull Player player) { this.player = player; } - public Player getPlayer() { - return this.player; - } - public void setPlayer(Player player) { if (this.player == null) { this.player = player; diff --git a/src/main/java/emu/grasscutter/game/player/BasePlayerManager.java b/src/main/java/emu/grasscutter/game/player/BasePlayerManager.java index 1a42840b5e4..c2447cefbde 100644 --- a/src/main/java/emu/grasscutter/game/player/BasePlayerManager.java +++ b/src/main/java/emu/grasscutter/game/player/BasePlayerManager.java @@ -2,10 +2,10 @@ import lombok.*; +@Getter public abstract class BasePlayerManager { protected final transient Player player; - @Getter @Setter(AccessLevel.PROTECTED) protected boolean loaded = false; @@ -13,10 +13,6 @@ public BasePlayerManager(@NonNull Player player) { this.player = player; } - public Player getPlayer() { - return this.player; - } - /** Saves the player to the database */ public void save() { getPlayer().save(); diff --git a/src/main/java/emu/grasscutter/game/player/InvokeHandler.java b/src/main/java/emu/grasscutter/game/player/InvokeHandler.java index b6e3e4c5aab..7bebf19fe9a 100644 --- a/src/main/java/emu/grasscutter/game/player/InvokeHandler.java +++ b/src/main/java/emu/grasscutter/game/player/InvokeHandler.java @@ -36,13 +36,13 @@ public synchronized void update(Player player) { } try { - if (entryListForwardAll.size() > 0) { + if (!entryListForwardAll.isEmpty()) { BasePacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAll); player.getScene().broadcastPacket(packet); this.entryListForwardAll.clear(); } - if (entryListForwardAllExceptCur.size() > 0) { + if (!entryListForwardAllExceptCur.isEmpty()) { BasePacket packet = packetClass .getDeclaredConstructor(List.class) @@ -50,7 +50,7 @@ public synchronized void update(Player player) { player.getScene().broadcastPacketToOthers(player, packet); this.entryListForwardAllExceptCur.clear(); } - if (entryListForwardHost.size() > 0) { + if (!entryListForwardHost.isEmpty()) { BasePacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardHost); player.getWorld().getHost().sendPacket(packet); diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 571da1f917e..684f1c1eb40 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -4,6 +4,7 @@ import emu.grasscutter.*; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.PlayerLevelData; +import emu.grasscutter.data.excels.scene.SceneTagData; import emu.grasscutter.data.excels.world.WeatherData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.*; @@ -78,17 +79,17 @@ public class Player implements PlayerHook, FieldFetch { @Getter private String signature; @Getter private int headImage; @Getter private int nameCardId = 210001; - @Getter private Position position; + @Getter private final Position position; @Getter @Setter private Position prevPos; @Getter @Setter private Position prevPosForHome; @Getter @Setter private int prevScene; - @Getter private Position rotation; + @Getter private final Position rotation; @Getter private PlayerBirthday birthday; @Getter private PlayerCodex codex; @Getter @Setter private boolean showAvatars; @Getter @Setter private List showAvatarList; @Getter @Setter private List showNameCardList; - @Getter private Map properties; + @Getter private final Map properties; @Getter @Setter private int currentRealmId; @Getter @Setter private transient boolean isInEditMode; @Getter @Setter private int widgetId; @@ -98,25 +99,25 @@ public class Player implements PlayerHook, FieldFetch { @Getter @Setter private boolean inGodMode; @Getter @Setter private boolean unlimitedStamina; - @Getter private Set nameCardList; - @Getter private Set flyCloakList; - @Getter private Set costumeList; - @Getter private Set personalLineList; + @Getter private final Set nameCardList; + @Getter private final Set flyCloakList; + @Getter private final Set costumeList; + @Getter private final Set personalLineList; @Getter @Setter private Set rewardedLevels; @Getter @Setter private Set homeRewardedLevels; @Getter @Setter private Set realmList; @Getter @Setter private Set seenRealmList; - @Getter private Set unlockedForgingBlueprints; - @Getter private Set unlockedCombines; - @Getter private Set unlockedFurniture; - @Getter private Set unlockedFurnitureSuite; - @Getter private Map expeditionInfo; - @Getter private Map unlockedRecipies; - @Getter private List activeForges; - @Getter private Map activeCookCompounds; - @Getter private Map questGlobalVariables; - @Getter private Map openStates; - @Getter private Map> sceneTags; + @Getter private final Set unlockedForgingBlueprints; + @Getter private final Set unlockedCombines; + @Getter private final Set unlockedFurniture; + @Getter private final Set unlockedFurnitureSuite; + @Getter private final Map expeditionInfo; + @Getter private final Map unlockedRecipies; + @Getter private final List activeForges; + @Getter private final Map activeCookCompounds; + @Getter private final Map questGlobalVariables; + @Getter private final Map openStates; + @Getter private final Map> sceneTags; @Getter @Setter private Map> unlockedSceneAreas; @Getter @Setter private Map> unlockedScenePoints; @Getter @Setter private List chatEmojiIdList; @@ -133,13 +134,13 @@ public class Player implements PlayerHook, FieldFetch { @Transient @Getter private int areaType = 0; // Player managers go here - @Getter private transient AvatarStorage avatars; - @Getter private transient Inventory inventory; - @Getter private transient FriendsList friendsList; - @Getter private transient MailHandler mailHandler; - @Getter private transient AbilityManager abilityManager; - @Getter private transient QuestManager questManager; - @Getter private transient TowerManager towerManager; + @Getter private final transient AvatarStorage avatars; + @Getter private final transient Inventory inventory; + @Getter private final transient FriendsList friendsList; + @Getter private final transient MailHandler mailHandler; + @Getter private final transient AbilityManager abilityManager; + @Getter private final transient QuestManager questManager; + @Getter private final transient TowerManager towerManager; @Getter private transient SotSManager sotsManager; @Getter private transient MapMarksManager mapMarksManager; @Getter private transient StaminaManager staminaManager; @@ -152,10 +153,10 @@ public class Player implements PlayerHook, FieldFetch { @Getter private transient CookingManager cookingManager; @Getter private transient CookingCompoundManager cookingCompoundManager; @Getter private transient ActivityManager activityManager; - @Getter private transient PlayerBuffManager buffManager; + @Getter private final transient PlayerBuffManager buffManager; @Getter private transient PlayerProgressManager progressManager; @Getter private transient SatiationManager satiationManager; - @Getter private transient TalkManager talkManager; + @Getter private final transient TalkManager talkManager; @Getter @Setter private transient Position lastCheckedPosition = null; @@ -164,9 +165,9 @@ public class Player implements PlayerHook, FieldFetch { private PlayerProfile playerProfile; // Getter has null-check @Getter private TeamManager teamManager; private TowerData towerData; // Getter has null-check - @Getter private PlayerGachaInfo gachaInfo; + @Getter private final PlayerGachaInfo gachaInfo; private PlayerCollectionRecords collectionRecordStore; // Getter has null-check - @Getter private ArrayList shopLimit; + @Getter private final ArrayList shopLimit; @Getter private transient GameHome home; @@ -194,11 +195,11 @@ public class Player implements PlayerHook, FieldFetch { @Getter @Setter private int nextResinRefresh; @Getter @Setter private int resinBuyCount; @Getter @Setter private int lastDailyReset; - @Getter private transient MpSettingType mpSetting = MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; + @Getter private final transient MpSettingType mpSetting = MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; @Getter private long playerGameTime = 540000; // 9 in-game hours. Present at the start of the game. - @Getter private PlayerProgress playerProgress; - @Getter private Set activeQuestTimers; + @Getter private final PlayerProgress playerProgress; + @Getter private final Set activeQuestTimers; @Getter @Setter private ElementType mainCharacterElement = ElementType.None; @@ -596,11 +597,9 @@ private void applyProperties() { */ private void applyStartingSceneTags() { GameData.getSceneTagDataMap().values().stream() - .filter(sceneTag -> sceneTag.isDefaultValid()) + .filter(SceneTagData::isDefaultValid) .forEach(sceneTag -> { - if (this.getSceneTags().get(sceneTag.getSceneId()) == null) { - this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>()); - } + this.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>()); this.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId()); }); } @@ -896,10 +895,8 @@ public ExpeditionInfo getExpeditionInfo(long avatarGuid) { } public ShopLimit getGoodsLimit(int goodsId) { - Optional shopLimit = this.shopLimit.stream().filter(x -> x.getShopGoodId() == goodsId).findFirst(); - if (shopLimit.isEmpty()) - return null; - return shopLimit.get(); + Optional limitOptional = this.shopLimit.stream().filter(x -> x.getShopGoodId() == goodsId).findFirst(); + return limitOptional.orElse(null); } public void addShopLimit(int goodsId, int boughtCount, int nextRefreshTime) { @@ -1207,7 +1204,7 @@ public PlayerCollectionRecords getCollectionRecordStore() { public Map getMapMarks() { if (this.mapMarks == null) { - this.mapMarks = new HashMap(); + this.mapMarks = new HashMap<>(); } return mapMarks; } @@ -1553,7 +1550,7 @@ public void unfreezeUnlockedScenePoints(int sceneId) { } public void unfreezeUnlockedScenePoints() { - unlockedScenePoints.keySet().forEach(sceneId -> unfreezeUnlockedScenePoints(sceneId)); + unlockedScenePoints.keySet().forEach(this::unfreezeUnlockedScenePoints); } public int getLegendaryKey() { @@ -1648,10 +1645,10 @@ public String toString() { .formatted(this.id, this.nickname, this.account); } + @Getter public enum SceneLoadState { NONE(0), LOADING(1), INIT(2), LOADED(3); - @Getter private final int value; SceneLoadState(int value) { diff --git a/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java b/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java index 85301daa626..7fa3f5f6e01 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java @@ -2,7 +2,9 @@ import dev.morphia.annotations.Entity; import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday; +import lombok.Getter; +@Getter @Entity public class PlayerBirthday { private int day; @@ -32,19 +34,11 @@ public PlayerBirthday set(int d, int m) { return this; } - public int getDay() { - return this.day; - } - public PlayerBirthday setDay(int value) { this.day = value; return this; } - public int getMonth() { - return this.month; - } - public PlayerBirthday setMonth(int value) { this.month = value; return this; diff --git a/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java b/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java index 9fc66d37e26..ca7a2dbdd11 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java @@ -178,7 +178,7 @@ public synchronized void onTick() { return true; }); - if (this.pendingBuffs.size() > 0) { + if (!this.pendingBuffs.isEmpty()) { // Send packet getPlayer() .sendPacket( diff --git a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java index 646ef22d1a2..fa8d42c0ff4 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java @@ -14,14 +14,14 @@ public class PlayerCodex { @Transient private Player player; // itemId is not codexId! - @Getter private Set unlockedWeapon; - @Getter private Map unlockedAnimal; - @Getter private Set unlockedMaterial; - @Getter private Set unlockedBook; - @Getter private Set unlockedTip; - @Getter private Set unlockedView; + @Getter private final Set unlockedWeapon; + @Getter private final Map unlockedAnimal; + @Getter private final Set unlockedMaterial; + @Getter private final Set unlockedBook; + @Getter private final Set unlockedTip; + @Getter private final Set unlockedView; @Getter private Set unlockedReliquary; - @Getter private Set unlockedReliquarySuitCodex; + @Getter private final Set unlockedReliquarySuitCodex; public PlayerCodex() { this.unlockedWeapon = new HashSet<>(); @@ -48,16 +48,14 @@ public void checkAddedItem(GameItem item) { val itemData = item.getItemData(); val itemId = item.getItemId(); switch (itemData.getItemType()) { - case ITEM_WEAPON -> { - Optional.ofNullable(GameData.getCodexWeaponDataIdMap().get(itemId)) - .ifPresent( - codexData -> { - if (this.getUnlockedWeapon().add(itemId)) { - this.player.save(); - this.player.sendPacket(new PacketCodexDataUpdateNotify(2, codexData.getId())); - } - }); - } + case ITEM_WEAPON -> Optional.ofNullable(GameData.getCodexWeaponDataIdMap().get(itemId)) + .ifPresent( + codexData -> { + if (this.getUnlockedWeapon().add(itemId)) { + this.player.save(); + this.player.sendPacket(new PacketCodexDataUpdateNotify(2, codexData.getId())); + } + }); case ITEM_MATERIAL -> { switch (itemData.getMaterialType()) { // Is this check even needed? @@ -65,17 +63,15 @@ public void checkAddedItem(GameItem item) { MATERIAL_WIDGET, MATERIAL_EXCHANGE, MATERIAL_AVATAR_MATERIAL, - MATERIAL_NOTICE_ADD_HP -> { - Optional.ofNullable(GameData.getCodexMaterialDataIdMap().get(itemId)) - .ifPresent( - codexData -> { - if (this.getUnlockedMaterial().add(itemId)) { - this.player.save(); - this.player.sendPacket( - new PacketCodexDataUpdateNotify(4, codexData.getId())); - } - }); - } + MATERIAL_NOTICE_ADD_HP -> Optional.ofNullable( + GameData.getCodexMaterialDataIdMap().get(itemId)) + .ifPresent( + codexData -> { + if (this.getUnlockedMaterial().add(itemId)) { + this.player.save(); + this.player.sendPacket(new PacketCodexDataUpdateNotify(4, codexData.getId())); + } + }); default -> {} } } diff --git a/src/main/java/emu/grasscutter/game/player/PlayerCollectionRecords.java b/src/main/java/emu/grasscutter/game/player/PlayerCollectionRecords.java index 1d1488bd4ec..35eab5b85e3 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerCollectionRecords.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerCollectionRecords.java @@ -2,6 +2,7 @@ import dev.morphia.annotations.Entity; import java.util.*; +import lombok.Getter; @Entity(useDiscriminator = false) public class PlayerCollectionRecords { @@ -43,6 +44,7 @@ public boolean findRecord(int configId) { } } + @Getter @Entity public static class CollectionRecord { private int configId; @@ -55,13 +57,5 @@ public CollectionRecord(int configId, long expiredTime) { this.configId = configId; this.expiredTime = expiredTime; } - - public int getConfigId() { - return configId; - } - - public long getExpiredTime() { - return expiredTime; - } } } diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java index f66b957ef75..dffaea0e84b 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java @@ -14,21 +14,21 @@ @Entity public class PlayerProgress { @Setter @Transient private Player player; - private Map itemHistory; + private final Map itemHistory; /* * A list of dungeon IDs which have been completed. * This only applies to one-time dungeons. */ - private IntArrayList completedDungeons; + private final IntArrayList completedDungeons; // keep track of EXEC_ADD_QUEST_PROGRESS count, will be used in CONTENT_ADD_QUEST_PROGRESS // not sure where to put this, this should be saved to DB but not to individual quest, since // it will be hard to loop and compare - private Map questProgressCountMap; + private final Map questProgressCountMap; - private Map itemGivings; - private Map bargains; + private final Map itemGivings; + private final Map bargains; public PlayerProgress() { this.questProgressCountMap = new ConcurrentHashMap<>(); @@ -83,11 +83,12 @@ public int resetCurrentProgress(String progressId) { return questProgressCountMap.merge(progressId, 0, Integer::min); } + @Getter @Entity @NoArgsConstructor public static class ItemEntry { - @Getter private int itemId; - @Getter @Setter private int obtainedCount; + private int itemId; + @Setter private int obtainedCount; ItemEntry(int itemId) { this.itemId = itemId; diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java index 7dfa50d48a5..b93968f94ee 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java @@ -19,7 +19,7 @@ // @Entity public final class PlayerProgressManager extends BasePlayerDataManager { /****************************************************************************************************************** - ****************************************************************************************************************** + *

* OPEN STATES ****************************************************************************************************************** *****************************************************************************************************************/ @@ -215,7 +215,7 @@ public void tryUnlockOpenStates() { } /****************************************************************************************************************** - ****************************************************************************************************************** + *

* MAP AREAS AND POINTS ****************************************************************************************************************** *****************************************************************************************************************/ @@ -313,7 +313,7 @@ public void addItemObtainedHistory(int id, int count) { } /****************************************************************************************************************** - ****************************************************************************************************************** + *

* SCENETAGS ****************************************************************************************************************** *****************************************************************************************************************/ diff --git a/src/main/java/emu/grasscutter/game/player/TeamInfo.java b/src/main/java/emu/grasscutter/game/player/TeamInfo.java index 794f36501f6..835e82d063b 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamInfo.java +++ b/src/main/java/emu/grasscutter/game/player/TeamInfo.java @@ -6,11 +6,14 @@ import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.net.proto.AvatarTeamOuterClass.AvatarTeam; import java.util.*; +import lombok.Getter; +import lombok.Setter; +@Getter @Entity public final class TeamInfo { - private String name; - private List avatars; + @Setter private String name; + private final List avatars; public TeamInfo() { this.name = ""; @@ -22,18 +25,6 @@ public TeamInfo(List avatars) { this.avatars = avatars; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getAvatars() { - return avatars; - } - public int size() { return avatars.size(); } diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index 86d7a0d4540..a29d4f0828d 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -83,7 +83,7 @@ public AbilityControlBlockOuterClass.AbilityControlBlock getAbilityControlBlock( int embryoId = 0; // add from default - if (Arrays.stream(GameConstants.DEFAULT_TEAM_ABILITY_STRINGS).count() > 0) { + if (Arrays.stream(GameConstants.DEFAULT_TEAM_ABILITY_STRINGS).findAny().isPresent()) { List teamAbilties = Arrays.stream(GameConstants.DEFAULT_TEAM_ABILITY_STRINGS).toList(); for (String skill : teamAbilties) { @@ -98,7 +98,7 @@ public AbilityControlBlockOuterClass.AbilityControlBlock getAbilityControlBlock( } // same as avatar ability hash (add frm levelEntityConfig data) - if (this.getTeamAbilityEmbryos().size() > 0) { + if (!this.getTeamAbilityEmbryos().isEmpty()) { for (String skill : this.getTeamAbilityEmbryos()) { AbilityEmbryoOuterClass.AbilityEmbryo emb = AbilityEmbryoOuterClass.AbilityEmbryo.newBuilder() @@ -257,7 +257,7 @@ public boolean addAvatarsToTeam(TeamInfo team, Collection avatars) { } // Convert avatars into a collection of avatar IDs, then add - team.getAvatars().addAll(avatars.stream().map(a -> a.getAvatarId()).toList()); + team.getAvatars().addAll(avatars.stream().map(Avatar::getAvatarId).toList()); // Update team if (this.getPlayer().isInMultiplayer()) { @@ -332,7 +332,7 @@ private void updateTeamResonances() { // Dual element resonances elementCounts.object2IntEntrySet().stream() .filter(e -> e.getIntValue() >= 2) - .map(e -> e.getKey()) + .map(Map.Entry::getKey) .filter(elementType -> elementType.getTeamResonanceId() != 0) .forEach( elementType -> { @@ -363,7 +363,7 @@ public void updateTeamProperties() { public void updateTeamEntities(BasePacket responsePacket) { // Sanity check - Should never happen - if (this.getCurrentTeamInfo().getAvatars().size() <= 0) { + if (this.getCurrentTeamInfo().getAvatars().size() == 0) { return; } @@ -495,7 +495,7 @@ public synchronized void setupAvatarTeam(int teamId, List list) { public void setupMpTeam(List list) { // Sanity checks - if (list.size() == 0 + if (list.isEmpty() || list.size() > this.getMaxTeamSize() || !this.getPlayer().isInMultiplayer()) { return; @@ -696,7 +696,7 @@ public void setupTemporaryTeam(List> guidList) { .map( list -> { // Sanity checks - if (list.size() == 0 || list.size() > this.getMaxTeamSize()) { + if (list.isEmpty() || list.size() > this.getMaxTeamSize()) { return null; } @@ -744,7 +744,7 @@ public synchronized void setCurrentTeam(int teamId) { // Get team TeamInfo teamInfo = this.getTeams().get(teamId); - if (teamInfo == null || teamInfo.getAvatars().size() == 0) { + if (teamInfo == null || teamInfo.getAvatars().isEmpty()) { return; } @@ -1054,7 +1054,7 @@ public void applyAbilities(Scene scene) { var avatarIds = scene.getSceneData().getSpecifiedAvatarList(); var specifiedAvatarList = this.getActiveTeam(); - if (avatarIds != null && avatarIds.size() > 0) { + if (avatarIds != null && !avatarIds.isEmpty()) { // certain scene could limit specific avatars' entry specifiedAvatarList.clear(); for (int id : avatarIds) { diff --git a/src/main/java/emu/grasscutter/game/props/ActionReason.java b/src/main/java/emu/grasscutter/game/props/ActionReason.java index 57867ed35f6..8e8a598f283 100644 --- a/src/main/java/emu/grasscutter/game/props/ActionReason.java +++ b/src/main/java/emu/grasscutter/game/props/ActionReason.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum ActionReason { None(0), QuestItem(1), @@ -205,8 +207,4 @@ public static ActionReason getTypeByValue(int value) { public static ActionReason getTypeByName(String name) { return stringMap.getOrDefault(name, None); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/BattlePassMissionRefreshType.java b/src/main/java/emu/grasscutter/game/props/BattlePassMissionRefreshType.java index d95a858a1c5..8f914114335 100644 --- a/src/main/java/emu/grasscutter/game/props/BattlePassMissionRefreshType.java +++ b/src/main/java/emu/grasscutter/game/props/BattlePassMissionRefreshType.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.props; +import lombok.Getter; + +@Getter public enum BattlePassMissionRefreshType { BATTLE_PASS_MISSION_REFRESH_DAILY(0), BATTLE_PASS_MISSION_REFRESH_CYCLE_CROSS_SCHEDULE(1), // Weekly @@ -11,8 +14,4 @@ public enum BattlePassMissionRefreshType { BattlePassMissionRefreshType(int value) { this.value = value; } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/BattlePassMissionStatus.java b/src/main/java/emu/grasscutter/game/props/BattlePassMissionStatus.java index 385f0775fc1..5cc8775153c 100644 --- a/src/main/java/emu/grasscutter/game/props/BattlePassMissionStatus.java +++ b/src/main/java/emu/grasscutter/game/props/BattlePassMissionStatus.java @@ -1,7 +1,9 @@ package emu.grasscutter.game.props; import emu.grasscutter.net.proto.BattlePassMissionOuterClass.BattlePassMission.MissionStatus; +import lombok.Getter; +@Getter public enum BattlePassMissionStatus { MISSION_STATUS_INVALID(0, MissionStatus.MISSION_STATUS_INVALID), MISSION_STATUS_UNFINISHED(1, MissionStatus.MISSION_STATUS_UNFINISHED), @@ -15,12 +17,4 @@ public enum BattlePassMissionStatus { this.value = value; this.missionStatus = missionStatus; // In case proto enum values change later } - - public int getValue() { - return value; - } - - public MissionStatus getMissionStatus() { - return missionStatus; - } } diff --git a/src/main/java/emu/grasscutter/game/props/CampTargetType.java b/src/main/java/emu/grasscutter/game/props/CampTargetType.java index a1076a0aeb5..2b9eca32461 100644 --- a/src/main/java/emu/grasscutter/game/props/CampTargetType.java +++ b/src/main/java/emu/grasscutter/game/props/CampTargetType.java @@ -4,7 +4,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum CampTargetType implements IntValueEnum { None(0), Alliance(1), @@ -32,10 +34,6 @@ private CampTargetType(int value) { this.value = value; } - public int getValue() { - return value; - } - public static CampTargetType getTypeByValue(int value) { return map.getOrDefault(value, None); } diff --git a/src/main/java/emu/grasscutter/game/props/ClimateType.java b/src/main/java/emu/grasscutter/game/props/ClimateType.java index 71a7c28e4da..582d13378a2 100644 --- a/src/main/java/emu/grasscutter/game/props/ClimateType.java +++ b/src/main/java/emu/grasscutter/game/props/ClimateType.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum ClimateType { CLIMATE_NONE(0), CLIMATE_SUNNY(1), @@ -45,10 +47,6 @@ public static ClimateType getTypeByShortName(String shortName) { return stringMap.getOrDefault(name, CLIMATE_NONE); } - public int getValue() { - return this.value; - } - public String getShortName() { return this.name().substring(8).toLowerCase(); } diff --git a/src/main/java/emu/grasscutter/game/props/ElementType.java b/src/main/java/emu/grasscutter/game/props/ElementType.java index 9ef59130c59..5a8c49725e3 100644 --- a/src/main/java/emu/grasscutter/game/props/ElementType.java +++ b/src/main/java/emu/grasscutter/game/props/ElementType.java @@ -7,6 +7,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum ElementType implements IntValueEnum { None(0, FightProperty.FIGHT_PROP_CUR_WIND_ENERGY, FightProperty.FIGHT_PROP_MAX_WIND_ENERGY), Fire( @@ -80,12 +81,12 @@ public enum ElementType implements IntValueEnum { }); } - @Getter private final int value; - @Getter private final int teamResonanceId; - @Getter private final FightProperty curEnergyProp; - @Getter private final FightProperty maxEnergyProp; - @Getter private final int depotIndex; - @Getter private final int configHash; + private final int value; + private final int teamResonanceId; + private final FightProperty curEnergyProp; + private final FightProperty maxEnergyProp; + private final int depotIndex; + private final int configHash; ElementType(int value, FightProperty curEnergyProp, FightProperty maxEnergyProp) { this(value, curEnergyProp, maxEnergyProp, 0, null, 0); diff --git a/src/main/java/emu/grasscutter/game/props/EnterReason.java b/src/main/java/emu/grasscutter/game/props/EnterReason.java index 7ef342e86d2..07d8ddf4c50 100644 --- a/src/main/java/emu/grasscutter/game/props/EnterReason.java +++ b/src/main/java/emu/grasscutter/game/props/EnterReason.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum EnterReason { None(0), Login(1), @@ -63,8 +65,4 @@ public static EnterReason getTypeByValue(int value) { public static EnterReason getTypeByName(String name) { return stringMap.getOrDefault(name, None); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/EntityIdType.java b/src/main/java/emu/grasscutter/game/props/EntityIdType.java index cee0a298198..e6e672a285e 100644 --- a/src/main/java/emu/grasscutter/game/props/EntityIdType.java +++ b/src/main/java/emu/grasscutter/game/props/EntityIdType.java @@ -1,7 +1,9 @@ package emu.grasscutter.game.props; import java.util.*; +import lombok.Getter; +@Getter public enum EntityIdType { AVATAR(0x01), MONSTER(0x02), @@ -34,8 +36,4 @@ public enum EntityIdType { public static EntityType toEntityType(int entityId) { return map.getOrDefault(entityId, EntityType.None); } - - public int getId() { - return id; - } } diff --git a/src/main/java/emu/grasscutter/game/props/EntityType.java b/src/main/java/emu/grasscutter/game/props/EntityType.java index 7d074b841d5..42eae8ed348 100644 --- a/src/main/java/emu/grasscutter/game/props/EntityType.java +++ b/src/main/java/emu/grasscutter/game/props/EntityType.java @@ -4,7 +4,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum EntityType implements IntValueEnum { None(0), Avatar(1), @@ -101,8 +103,4 @@ public static EntityType getTypeByValue(int value) { public static EntityType getTypeByName(String name) { return stringMap.getOrDefault(name, None); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/FetterState.java b/src/main/java/emu/grasscutter/game/props/FetterState.java index aac46461df5..1498a60be79 100644 --- a/src/main/java/emu/grasscutter/game/props/FetterState.java +++ b/src/main/java/emu/grasscutter/game/props/FetterState.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum FetterState { NONE(0), NOT_OPEN(1), @@ -35,8 +37,4 @@ public static FetterState getTypeByValue(int value) { public static FetterState getTypeByName(String name) { return stringMap.getOrDefault(name, NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/FightProperty.java b/src/main/java/emu/grasscutter/game/props/FightProperty.java index f94bc78a544..bd49904951b 100644 --- a/src/main/java/emu/grasscutter/game/props/FightProperty.java +++ b/src/main/java/emu/grasscutter/game/props/FightProperty.java @@ -8,6 +8,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum FightProperty { FIGHT_PROP_NONE(0), FIGHT_PROP_BASE_HP(1), @@ -240,10 +241,6 @@ public static boolean isPercentage(FightProperty prop) { return !flatProps.contains(prop); } - public int getId() { - return id; - } - @Getter public static class CompoundProperty { private final FightProperty result; diff --git a/src/main/java/emu/grasscutter/game/props/GrowCurve.java b/src/main/java/emu/grasscutter/game/props/GrowCurve.java index 2ec0db35da2..a04c42205e4 100644 --- a/src/main/java/emu/grasscutter/game/props/GrowCurve.java +++ b/src/main/java/emu/grasscutter/game/props/GrowCurve.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum GrowCurve { GROW_CURVE_NONE(0), GROW_CURVE_HP(1), @@ -96,8 +98,4 @@ public static GrowCurve getPropById(int value) { public static GrowCurve getPropByName(String name) { return stringMap.getOrDefault(name, GROW_CURVE_NONE); } - - public int getId() { - return id; - } } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainAvatar.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainAvatar.java index 1dae2822d48..add08558d97 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainAvatar.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseGainAvatar.java @@ -1,5 +1,6 @@ package emu.grasscutter.game.props.ItemUseAction; +import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.props.ItemUseOp; import emu.grasscutter.game.systems.InventorySystem; @@ -43,7 +44,7 @@ public boolean useItem(UseItemParams params) { int itemId = Optional.ofNullable(params.player.getAvatars().getAvatarById(this.i)) .map(Avatar::getSkillDepot) - .map(depot -> depot.getTalentCostItemId()) + .map(AvatarSkillDepotData::getTalentCostItemId) .orElse((this.i % 1000) + 100); return params.player.getInventory().addItem(itemId); } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseInt.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseInt.java index 34ec476d880..dd0eec6818e 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseInt.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseInt.java @@ -2,8 +2,9 @@ import lombok.Getter; +@Getter public abstract class ItemUseInt extends ItemUseAction { - @Getter protected int i = 0; + protected int i = 0; public ItemUseInt(String[] useParam) { try { diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java index d5f946735f3..da319d3a902 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/UseItemParams.java @@ -6,8 +6,8 @@ public class UseItemParams { // Don't want to change 40 method signatures when this gets extended! - public Player player; - public ItemUseTarget itemUseTarget; + public final Player player; + public final ItemUseTarget itemUseTarget; public Avatar targetAvatar = null; public int count = 1; public int optionId = 0; diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseOp.java b/src/main/java/emu/grasscutter/game/props/ItemUseOp.java index 7ff42db0b5e..54cc2a6d1e3 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseOp.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseOp.java @@ -2,7 +2,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum ItemUseOp { ITEM_USE_NONE(0), ITEM_USE_ACCEPT_QUEST(1), @@ -50,11 +52,7 @@ public enum ItemUseOp { private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); static { - Stream.of(values()) - .forEach( - e -> { - map.put(e.getValue(), e); - }); + Stream.of(values()).forEach(e -> map.put(e.getValue(), e)); } private final int value; @@ -66,8 +64,4 @@ public enum ItemUseOp { public static ItemUseOp getTypeByValue(int value) { return map.getOrDefault(value, ITEM_USE_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseTarget.java b/src/main/java/emu/grasscutter/game/props/ItemUseTarget.java index 99641d0850c..07701f36ac6 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseTarget.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseTarget.java @@ -2,7 +2,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum ItemUseTarget { ITEM_USE_TARGET_NONE(0), ITEM_USE_TARGET_CUR_AVATAR(1), @@ -14,11 +16,7 @@ public enum ItemUseTarget { private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); static { - Stream.of(values()) - .forEach( - e -> { - map.put(e.getValue(), e); - }); + Stream.of(values()).forEach(e -> map.put(e.getValue(), e)); } private final int value; @@ -30,8 +28,4 @@ public enum ItemUseTarget { public static ItemUseTarget getTypeByValue(int value) { return map.getOrDefault(value, ITEM_USE_TARGET_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/LifeState.java b/src/main/java/emu/grasscutter/game/props/LifeState.java index 1785b2fafec..e708d534a56 100644 --- a/src/main/java/emu/grasscutter/game/props/LifeState.java +++ b/src/main/java/emu/grasscutter/game/props/LifeState.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum LifeState { LIFE_NONE(0), LIFE_ALIVE(1), @@ -35,8 +37,4 @@ public static LifeState getTypeByValue(int value) { public static LifeState getTypeByName(String name) { return stringMap.getOrDefault(name, LIFE_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/MonsterType.java b/src/main/java/emu/grasscutter/game/props/MonsterType.java index 69558ee83a9..f2b3703771c 100644 --- a/src/main/java/emu/grasscutter/game/props/MonsterType.java +++ b/src/main/java/emu/grasscutter/game/props/MonsterType.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum MonsterType { MONSTER_NONE(0), MONSTER_ORDINARY(1), @@ -37,8 +39,4 @@ public static MonsterType getTypeByValue(int value) { public static MonsterType getTypeByName(String name) { return stringMap.getOrDefault(name, MONSTER_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/PlayerProperty.java b/src/main/java/emu/grasscutter/game/props/PlayerProperty.java index 4c5995873df..9c4d40b5963 100644 --- a/src/main/java/emu/grasscutter/game/props/PlayerProperty.java +++ b/src/main/java/emu/grasscutter/game/props/PlayerProperty.java @@ -4,6 +4,7 @@ import java.util.stream.Stream; import lombok.Getter; +@Getter public enum PlayerProperty { PROP_NONE(0), PROP_EXP(1001, 0), @@ -73,8 +74,8 @@ public enum PlayerProperty { Stream.of(values()).forEach(e -> map.put(e.getId(), e)); } - @Getter private final int id, min, max; - @Getter private final boolean dynamicRange; + private final int id, min, max; + private final boolean dynamicRange; PlayerProperty(int id, int min, int max, boolean dynamicRange) { this.id = id; diff --git a/src/main/java/emu/grasscutter/game/props/RefreshType.java b/src/main/java/emu/grasscutter/game/props/RefreshType.java index 8f1baa132c0..bf362f2b11e 100644 --- a/src/main/java/emu/grasscutter/game/props/RefreshType.java +++ b/src/main/java/emu/grasscutter/game/props/RefreshType.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum RefreshType { REFRESH_NONE(0), REFRESH_INTERVAL(1), @@ -28,10 +30,6 @@ private RefreshType(int value) { this.value = value; } - public int getValue() { - return value; - } - public static RefreshType getTypeByValue(int value) { return map.getOrDefault(value, REFRESH_NONE); } diff --git a/src/main/java/emu/grasscutter/game/props/SceneType.java b/src/main/java/emu/grasscutter/game/props/SceneType.java index 09bd084b3fe..bf66d3277ff 100644 --- a/src/main/java/emu/grasscutter/game/props/SceneType.java +++ b/src/main/java/emu/grasscutter/game/props/SceneType.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum SceneType { SCENE_NONE(0), SCENE_WORLD(1), @@ -38,8 +40,4 @@ public static SceneType getTypeByValue(int value) { public static SceneType getTypeByName(String name) { return stringMap.getOrDefault(name, SCENE_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/ServerBuffType.java b/src/main/java/emu/grasscutter/game/props/ServerBuffType.java index b9a08259090..00ebb0e34b3 100644 --- a/src/main/java/emu/grasscutter/game/props/ServerBuffType.java +++ b/src/main/java/emu/grasscutter/game/props/ServerBuffType.java @@ -2,7 +2,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum ServerBuffType { SERVER_BUFF_NONE(0), SERVER_BUFF_AVATAR(1), @@ -12,11 +14,7 @@ public enum ServerBuffType { private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); static { - Stream.of(values()) - .forEach( - e -> { - map.put(e.getValue(), e); - }); + Stream.of(values()).forEach(e -> map.put(e.getValue(), e)); } private final int value; @@ -28,8 +26,4 @@ public enum ServerBuffType { public static ServerBuffType getTypeByValue(int value) { return map.getOrDefault(value, SERVER_BUFF_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/WatcherTriggerType.java b/src/main/java/emu/grasscutter/game/props/WatcherTriggerType.java index 98ae0a3c378..432f0b61bd7 100644 --- a/src/main/java/emu/grasscutter/game/props/WatcherTriggerType.java +++ b/src/main/java/emu/grasscutter/game/props/WatcherTriggerType.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum WatcherTriggerType { TRIGGER_NONE(0), TRIGGER_COMBAT_CONFIG_COMMON(1), @@ -330,8 +332,4 @@ public static WatcherTriggerType getTypeByValue(int value) { public static WatcherTriggerType getTypeByName(String name) { return stringMap.getOrDefault(name, TRIGGER_NONE); } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/props/WeaponType.java b/src/main/java/emu/grasscutter/game/props/WeaponType.java index 5d1b9640d20..b43d1c7a487 100644 --- a/src/main/java/emu/grasscutter/game/props/WeaponType.java +++ b/src/main/java/emu/grasscutter/game/props/WeaponType.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum WeaponType { WEAPON_NONE(0), WEAPON_SWORD_ONE_HAND(1, 10, 5), @@ -53,16 +55,4 @@ public static WeaponType getTypeByValue(int value) { public static WeaponType getTypeByName(String name) { return stringMap.getOrDefault(name, WEAPON_NONE); } - - public int getValue() { - return value; - } - - public int getEnergyGainInitialProbability() { - return energyGainInitialProbability; - } - - public int getEnergyGainIncreaseProbability() { - return energyGainIncreaseProbability; - } } diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index 7888e470138..b2e0b974a47 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -67,7 +67,7 @@ public void start() { questData.getFinishCond().stream() .filter(p -> p.getType() == QuestContent.QUEST_CONTENT_TRIGGER_FIRE) .toList(); - if (triggerCond.size() > 0) { + if (!triggerCond.isEmpty()) { for (val cond : triggerCond) { var newTrigger = GameData.getTriggerExcelConfigDataMap().get(cond.getParam()[0]); if (newTrigger != null) { @@ -158,14 +158,14 @@ public void setFailProgress(int index, int value) { public boolean clearProgress(boolean notifyDelete) { // TODO improve var oldState = state; - if (questData.getAcceptCond() != null && questData.getAcceptCond().size() != 0) { + if (questData.getAcceptCond() != null && !questData.getAcceptCond().isEmpty()) { this.getMainQuest() .getQuestManager() .getAcceptProgressLists() .put(this.getSubQuestId(), new int[questData.getAcceptCond().size()]); } - if (questData.getFinishCond() != null && questData.getFinishCond().size() != 0) { + if (questData.getFinishCond() != null && !questData.getFinishCond().isEmpty()) { for (var condition : questData.getFinishCond()) { if (condition.getType() == QuestContent.QUEST_CONTENT_LUA_NOTIFY) { this.getOwner().getPlayerProgress().resetCurrentProgress(condition.getParamStr()); @@ -174,7 +174,7 @@ public boolean clearProgress(boolean notifyDelete) { this.finishProgressList = new int[questData.getFinishCond().size()]; } - if (questData.getFailCond() != null && questData.getFailCond().size() != 0) { + if (questData.getFailCond() != null && !questData.getFailCond().isEmpty()) { for (var condition : questData.getFailCond()) { if (condition.getType() == QuestContent.QUEST_CONTENT_LUA_NOTIFY) { this.getOwner().getPlayerProgress().resetCurrentProgress(condition.getParamStr()); @@ -294,10 +294,7 @@ public void fail() { public boolean rewind(boolean notifyDelete) { getMainQuest().getChildQuests().values().stream() .filter(p -> p.getQuestData().getOrder() > this.getQuestData().getOrder()) - .forEach( - q -> { - q.clearProgress(notifyDelete); - }); + .forEach(q -> q.clearProgress(notifyDelete)); clearProgress(notifyDelete); this.start(); return true; diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index 2ac3601ab15..cdd40945dec 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -26,7 +26,7 @@ public final class QuestManager extends BasePlayerManager { @Getter private final Player player; @Getter private final Int2ObjectMap mainQuests; - @Getter private Int2ObjectMap acceptProgressLists; + @Getter private final Int2ObjectMap acceptProgressLists; @Getter private final List loggedQuests; private long lastHourCheck = 0; diff --git a/src/main/java/emu/grasscutter/game/quest/RewindData.java b/src/main/java/emu/grasscutter/game/quest/RewindData.java index d17ee1876f6..8255932978c 100644 --- a/src/main/java/emu/grasscutter/game/quest/RewindData.java +++ b/src/main/java/emu/grasscutter/game/quest/RewindData.java @@ -8,9 +8,10 @@ public class RewindData { AvatarData avatar; List npcs; + @Getter @Data public static class AvatarData { - @Getter private String pos; + private String pos; } @Data diff --git a/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java b/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java index 17d7aac83cb..ebb3bb903db 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/LogicType.java @@ -3,8 +3,10 @@ import emu.grasscutter.Grasscutter; import java.util.*; import java.util.function.BooleanSupplier; +import lombok.Getter; import org.jetbrains.annotations.NotNull; +@Getter public enum LogicType { LOGIC_NONE(0), LOGIC_AND(1), @@ -88,8 +90,4 @@ public static boolean calculate(@NotNull LogicType logicType, List contentMap = new Int2ObjectOpenHashMap<>(); private static final Map contentStringMap = new HashMap<>(); diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java index a7e66b874b7..2851265bfab 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestContent.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum QuestContent implements QuestTrigger { QUEST_CONTENT_NONE(0), QUEST_CONTENT_KILL_MONSTER(1), // currently unused @@ -88,10 +90,6 @@ public enum QuestContent implements QuestTrigger { this.value = id; } - public int getValue() { - return value; - } - private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); private static final Map contentStringMap = new HashMap<>(); diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java index 31924ca12e1..6a339c0846e 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestExec.java @@ -3,7 +3,9 @@ import it.unimi.dsi.fastutil.ints.*; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; +@Getter public enum QuestExec implements QuestTrigger { QUEST_EXEC_NONE(0), QUEST_EXEC_DEL_PACK_ITEM(1), @@ -85,10 +87,6 @@ public enum QuestExec implements QuestTrigger { this.value = id; } - public int getValue() { - return value; - } - private static final Int2ObjectMap contentMap = new Int2ObjectOpenHashMap<>(); private static final Map contentStringMap = new HashMap<>(); diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestGuideType.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestGuideType.java index 90cd6ea2d04..3c872a621c9 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestGuideType.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestGuideType.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.quest.enums; +import lombok.Getter; + +@Getter public enum QuestGuideType { QUEST_GUIDE_NONE(0), QUEST_GUIDE_LOCATION(1), @@ -10,8 +13,4 @@ public enum QuestGuideType { QuestGuideType(int id) { this.value = id; } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestShowType.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestShowType.java index 2ea9c61f44e..ef59d1a10dc 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestShowType.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestShowType.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.quest.enums; +import lombok.Getter; + +@Getter public enum QuestShowType { QUEST_SHOW(0), QUEST_HIDDEN(1); @@ -9,8 +12,4 @@ public enum QuestShowType { QuestShowType(int id) { this.value = id; } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java index 0bccccb3496..04bf4dad2d8 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestState.java @@ -1,7 +1,9 @@ package emu.grasscutter.game.quest.enums; import emu.grasscutter.scripts.constants.IntValueEnum; +import lombok.Getter; +@Getter public enum QuestState implements IntValueEnum { QUEST_STATE_NONE(0), QUEST_STATE_UNSTARTED(1), @@ -21,8 +23,4 @@ public enum QuestState implements IntValueEnum { QuestState(int id) { this.value = id; } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/quest/enums/QuestType.java b/src/main/java/emu/grasscutter/game/quest/enums/QuestType.java index be1e31fe71f..f0fda0812df 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/QuestType.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/QuestType.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.quest.enums; +import lombok.Getter; + +@Getter public enum QuestType { AQ(0), FQ(1), @@ -15,8 +18,4 @@ public enum QuestType { QuestType(int id) { this.value = id; } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/quest/enums/ShowQuestGuideType.java b/src/main/java/emu/grasscutter/game/quest/enums/ShowQuestGuideType.java index d59d1737bd1..6ae10e7782c 100644 --- a/src/main/java/emu/grasscutter/game/quest/enums/ShowQuestGuideType.java +++ b/src/main/java/emu/grasscutter/game/quest/enums/ShowQuestGuideType.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.quest.enums; +import lombok.Getter; + +@Getter public enum ShowQuestGuideType { QUEST_GUIDE_ITEM_ENABLE(0), QUEST_GUIDE_ITEM_DISABLE(1), @@ -10,8 +13,4 @@ public enum ShowQuestGuideType { ShowQuestGuideType(int id) { this.value = id; } - - public int getValue() { - return value; - } } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java index c4e98647646..ef11c0e9349 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecDecQuestGlobalVar.java @@ -12,7 +12,7 @@ public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, Stri quest .getOwner() .getQuestManager() - .decQuestGlobalVarValue(Integer.valueOf(paramStr[0]), Integer.valueOf(paramStr[1])); + .decQuestGlobalVarValue(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); return true; } } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java index 0d1af571716..8b0a92d5869 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java @@ -12,7 +12,7 @@ public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, Stri quest .getOwner() .getQuestManager() - .incQuestGlobalVarValue(Integer.valueOf(paramStr[0]), Integer.valueOf(paramStr[1])); + .incQuestGlobalVarValue(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); return true; } } diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java index fe1630ff982..eeb09d9db61 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java @@ -12,7 +12,7 @@ public boolean execute(GameQuest quest, QuestData.QuestExecParam condition, Stri quest .getOwner() .getQuestManager() - .setQuestGlobalVarValue(Integer.valueOf(paramStr[0]), Integer.valueOf(paramStr[1])); + .setQuestGlobalVarValue(Integer.parseInt(paramStr[0]), Integer.parseInt(paramStr[1])); return true; } } diff --git a/src/main/java/emu/grasscutter/game/shop/ShopInfo.java b/src/main/java/emu/grasscutter/game/shop/ShopInfo.java index 76119984e47..f2418c4c355 100644 --- a/src/main/java/emu/grasscutter/game/shop/ShopInfo.java +++ b/src/main/java/emu/grasscutter/game/shop/ShopInfo.java @@ -71,7 +71,7 @@ private boolean evaluateVirtualCost(ItemParamData item) { } public void removeVirtualCosts() { - if (this.costItemList != null) this.costItemList.removeIf(item -> evaluateVirtualCost(item)); + if (this.costItemList != null) this.costItemList.removeIf(this::evaluateVirtualCost); } public enum ShopRefreshType { diff --git a/src/main/java/emu/grasscutter/game/shop/ShopLimit.java b/src/main/java/emu/grasscutter/game/shop/ShopLimit.java index 827826803cc..ae9a2d3488e 100644 --- a/src/main/java/emu/grasscutter/game/shop/ShopLimit.java +++ b/src/main/java/emu/grasscutter/game/shop/ShopLimit.java @@ -1,43 +1,15 @@ package emu.grasscutter.game.shop; import dev.morphia.annotations.Entity; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter @Entity public class ShopLimit { private int shopGoodId; private int hasBought; private int hasBoughtInPeriod = 0; private int nextRefreshTime = 0; - - public int getShopGoodId() { - return shopGoodId; - } - - public void setShopGoodId(int shopGoodId) { - this.shopGoodId = shopGoodId; - } - - public int getHasBought() { - return hasBought; - } - - public void setHasBought(int hasBought) { - this.hasBought = hasBought; - } - - public int getNextRefreshTime() { - return nextRefreshTime; - } - - public void setNextRefreshTime(int nextRefreshTime) { - this.nextRefreshTime = nextRefreshTime; - } - - public int getHasBoughtInPeriod() { - return hasBoughtInPeriod; - } - - public void setHasBoughtInPeriod(int hasBoughtInPeriod) { - this.hasBoughtInPeriod = hasBoughtInPeriod; - } } diff --git a/src/main/java/emu/grasscutter/game/shop/ShopSystem.java b/src/main/java/emu/grasscutter/game/shop/ShopSystem.java index f3ce4679a3c..6f0edc176ed 100644 --- a/src/main/java/emu/grasscutter/game/shop/ShopSystem.java +++ b/src/main/java/emu/grasscutter/game/shop/ShopSystem.java @@ -10,11 +10,12 @@ import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.*; import java.util.*; +import lombok.Getter; public class ShopSystem extends BaseGameSystem { private static final int REFRESH_HOUR = 4; // In GMT+8 server private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone - private final Int2ObjectMap> shopData; + @Getter private final Int2ObjectMap> shopData; private final Int2ObjectMap> shopChestData; public ShopSystem(GameServer server) { @@ -36,10 +37,6 @@ public static int getShopNextRefreshTime(ShopInfo shopInfo) { }; } - public Int2ObjectMap> getShopData() { - return shopData; - } - public List getShopChestData(int chestId) { return this.shopChestData.get(chestId); } @@ -48,7 +45,7 @@ private void loadShop() { getShopData().clear(); try { List banners = DataLoader.loadList("Shop.json", ShopTable.class); - if (banners.size() > 0) { + if (!banners.isEmpty()) { for (ShopTable shopTable : banners) { shopTable.getItems().forEach(ShopInfo::removeVirtualCosts); getShopData().put(shopTable.getShopId(), shopTable.getItems()); @@ -93,7 +90,7 @@ private void loadShopChest() { } this.shopChestData.put((int) chestId, list); }); - Grasscutter.getLogger().debug("Loaded " + chestMap.size() + " ShopChest entries."); + Grasscutter.getLogger().debug("Loaded {} ShopChest entries.", chestMap.size()); } catch (Exception e) { Grasscutter.getLogger().error("Unable to load ShopChest data.", e); } diff --git a/src/main/java/emu/grasscutter/game/shop/ShopTable.java b/src/main/java/emu/grasscutter/game/shop/ShopTable.java index a2990d7ff0c..459f843b7c8 100644 --- a/src/main/java/emu/grasscutter/game/shop/ShopTable.java +++ b/src/main/java/emu/grasscutter/game/shop/ShopTable.java @@ -1,24 +1,12 @@ package emu.grasscutter.game.shop; import java.util.*; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class ShopTable { private int shopId; private List items = new ArrayList<>(); - - public int getShopId() { - return shopId; - } - - public void setShopId(int shopId) { - this.shopId = shopId; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } } diff --git a/src/main/java/emu/grasscutter/game/systems/AnnouncementSystem.java b/src/main/java/emu/grasscutter/game/systems/AnnouncementSystem.java index 16bf1b23f95..6d21eb05285 100644 --- a/src/main/java/emu/grasscutter/game/systems/AnnouncementSystem.java +++ b/src/main/java/emu/grasscutter/game/systems/AnnouncementSystem.java @@ -44,7 +44,7 @@ public List getOnlinePlayers() { } public void broadcast(List tpl) { - if (tpl == null || tpl.size() == 0) { + if (tpl == null || tpl.isEmpty()) { return; } diff --git a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java index 3072eebab19..47c9affc015 100644 --- a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java +++ b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java @@ -25,7 +25,7 @@ public class InventorySystem extends BaseGameSystem { private static final Int2IntMap weaponRefundMaterials = new Int2IntArrayMap(); - { + static { // Use a sorted map, use exp as key to sort by exp // We want to have weaponRefundMaterials as (id, exp) in descending exp order var temp = new Int2IntRBTreeMap(Collections.reverseOrder()); @@ -58,7 +58,7 @@ public static synchronized int checkPlayerAvatarConstellationLevel(Player player } else { avatarId = Optional.ofNullable(GameData.getItemDataMap().get(id)) - .map(itemData -> itemData.getItemUseActions()) + .map(ItemData::getItemUseActions) .flatMap( actions -> actions.stream() @@ -83,11 +83,9 @@ public static synchronized int checkPlayerAvatarConstellationLevel(Player player if (avatarData == null) { Grasscutter.getLogger() .error( - "Attempted to check constellation level for UID" - + player.getUid() - + "'s avatar " - + avatarId - + " but avatar has no skillDepot!"); + "Attempted to check constellation level for UID{}'s avatar {} but avatar has no skillDepot!", + player.getUid(), + avatarId); return 0; } int constItemId = avatarData.getTalentCostItemId(); @@ -122,7 +120,7 @@ public void upgradeRelic( int moraCost = 0; int expGain = 0; - List foodRelics = new ArrayList(); + List foodRelics = new ArrayList<>(); for (long guid : foodRelicList) { // Add to delete queue GameItem food = player.getInventory().getItemByGuid(guid); @@ -139,7 +137,7 @@ public void upgradeRelic( } foodRelics.add(food); } - List payList = new ArrayList(); + List payList = new ArrayList<>(); for (ItemParam itemParam : list) { int amount = itemParam @@ -347,7 +345,7 @@ public void upgradeWeapon( // Get exp gain int expGain = 0, expGainFree = 0; - List foodWeapons = new ArrayList(); + List foodWeapons = new ArrayList<>(); for (long guid : foodWeaponGuidList) { GameItem food = player.getInventory().getItemByGuid(guid); if (food == null || !food.isDestroyable()) { @@ -359,7 +357,7 @@ public void upgradeWeapon( } foodWeapons.add(food); } - List payList = new ArrayList(); + List payList = new ArrayList<>(); for (ItemParam param : itemParamList) { int amount = param.getCount(); // Previously this capped to inventory amount, but rejecting the payment @@ -482,7 +480,7 @@ public void refineWeapon(Player player, long targetGuid, long feedGuid) { if (weapon.getRefinement() >= 4 || weapon.getAffixes() == null - || weapon.getAffixes().size() == 0) { + || weapon.getAffixes().isEmpty()) { return; } @@ -818,7 +816,7 @@ public void destroyMaterial(Player player, List list) { } // Give back items - if (returnMaterialMap.size() > 0) { + if (!returnMaterialMap.isEmpty()) { returnMaterialMap.forEach((id, count) -> inventory.addItem(new GameItem(id, count))); } diff --git a/src/main/java/emu/grasscutter/game/talk/TalkExec.java b/src/main/java/emu/grasscutter/game/talk/TalkExec.java index f6a7aefde74..0e92462cc12 100644 --- a/src/main/java/emu/grasscutter/game/talk/TalkExec.java +++ b/src/main/java/emu/grasscutter/game/talk/TalkExec.java @@ -5,6 +5,7 @@ import java.util.stream.Stream; import lombok.*; +@Getter @AllArgsConstructor public enum TalkExec { TALK_EXEC_NONE(0), @@ -56,5 +57,5 @@ public static TalkExec getExecByName(String name) { return execStringMap.getOrDefault(name, TALK_EXEC_NONE); } - @Getter private final int value; + private final int value; } diff --git a/src/main/java/emu/grasscutter/game/tower/TowerLevelRecord.java b/src/main/java/emu/grasscutter/game/tower/TowerLevelRecord.java index 245ec327df0..997c40ded05 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerLevelRecord.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerLevelRecord.java @@ -2,7 +2,11 @@ import dev.morphia.annotations.Entity; import java.util.*; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter @Entity public class TowerLevelRecord { /** floorId in config */ @@ -32,28 +36,4 @@ public int getLevelStars(int levelId) { public int getStarCount() { return passedLevelMap.values().stream().mapToInt(Integer::intValue).sum(); } - - public int getFloorId() { - return floorId; - } - - public void setFloorId(int floorId) { - this.floorId = floorId; - } - - public Map getPassedLevelMap() { - return passedLevelMap; - } - - public void setPassedLevelMap(Map passedLevelMap) { - this.passedLevelMap = passedLevelMap; - } - - public int getFloorStarRewardProgress() { - return floorStarRewardProgress; - } - - public void setFloorStarRewardProgress(int floorStarRewardProgress) { - this.floorStarRewardProgress = floorStarRewardProgress; - } } diff --git a/src/main/java/emu/grasscutter/game/tower/TowerManager.java b/src/main/java/emu/grasscutter/game/tower/TowerManager.java index 505543c12f8..b81d206ab72 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerManager.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerManager.java @@ -71,7 +71,7 @@ public void onEnd() { public Map getRecordMap() { Map recordMap = getTowerData().recordMap; - if (recordMap == null || recordMap.size() == 0) { + if (recordMap == null || recordMap.isEmpty()) { recordMap = new HashMap<>(); recordMap.put(1001, new TowerLevelRecord(1001)); getTowerData().recordMap = recordMap; diff --git a/src/main/java/emu/grasscutter/game/tower/TowerScheduleConfig.java b/src/main/java/emu/grasscutter/game/tower/TowerScheduleConfig.java index ae6f86b00b4..a3f539b1356 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerScheduleConfig.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerScheduleConfig.java @@ -1,34 +1,14 @@ package emu.grasscutter.game.tower; import java.util.Date; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class TowerScheduleConfig { private int scheduleId; private Date scheduleStartTime; private Date nextScheduleChangeTime; - - public int getScheduleId() { - return scheduleId; - } - - public void setScheduleId(int scheduleId) { - this.scheduleId = scheduleId; - } - - public Date getScheduleStartTime() { - return scheduleStartTime; - } - - public void setScheduleStartTime(Date scheduleStartTime) { - this.scheduleStartTime = scheduleStartTime; - } - - public Date getNextScheduleChangeTime() { - return nextScheduleChangeTime; - } - - public void setNextScheduleChangeTime(Date nextScheduleChangeTime) { - this.nextScheduleChangeTime = nextScheduleChangeTime; - } } diff --git a/src/main/java/emu/grasscutter/game/tower/TowerSystem.java b/src/main/java/emu/grasscutter/game/tower/TowerSystem.java index 18c1036cdeb..0d28d1a703f 100644 --- a/src/main/java/emu/grasscutter/game/tower/TowerSystem.java +++ b/src/main/java/emu/grasscutter/game/tower/TowerSystem.java @@ -5,7 +5,9 @@ import emu.grasscutter.data.excels.tower.TowerScheduleData; import emu.grasscutter.server.game.*; import java.util.*; +import lombok.Getter; +@Getter public class TowerSystem extends BaseGameSystem { private TowerScheduleConfig towerScheduleConfig; @@ -23,10 +25,6 @@ public synchronized void load() { } } - public TowerScheduleConfig getTowerScheduleConfig() { - return towerScheduleConfig; - } - public TowerScheduleData getCurrentTowerScheduleData() { var data = GameData.getTowerScheduleDataMap().get(towerScheduleConfig.getScheduleId()); if (data == null) { diff --git a/src/main/java/emu/grasscutter/game/world/GridPosition.java b/src/main/java/emu/grasscutter/game/world/GridPosition.java index b4a47b43c2a..a90cc315954 100644 --- a/src/main/java/emu/grasscutter/game/world/GridPosition.java +++ b/src/main/java/emu/grasscutter/game/world/GridPosition.java @@ -6,15 +6,17 @@ import java.util.List; import lombok.*; +@Setter +@Getter @Entity public final class GridPosition implements Serializable { - private static final long serialVersionUID = -2001232300615923575L; + @Serial private static final long serialVersionUID = -2001232300615923575L; - @Getter @Setter private int x; + private int x; - @Getter @Setter private int z; + private int z; - @Getter @Setter private int width; + private int width; public GridPosition() {} diff --git a/src/main/java/emu/grasscutter/game/world/Location.java b/src/main/java/emu/grasscutter/game/world/Location.java index e6f5ca4fb76..e25fa3b1096 100644 --- a/src/main/java/emu/grasscutter/game/world/Location.java +++ b/src/main/java/emu/grasscutter/game/world/Location.java @@ -3,9 +3,11 @@ import dev.morphia.annotations.*; import lombok.*; +@Setter +@Getter @Entity public class Location extends Position { - @Transient @Getter @Setter private Scene scene; + @Transient private Scene scene; public Location(Scene scene, Position position) { this.set(position); diff --git a/src/main/java/emu/grasscutter/game/world/Position.java b/src/main/java/emu/grasscutter/game/world/Position.java index 780a6c2138f..b885ec4c88d 100644 --- a/src/main/java/emu/grasscutter/game/world/Position.java +++ b/src/main/java/emu/grasscutter/game/world/Position.java @@ -5,15 +5,18 @@ import dev.morphia.annotations.Entity; import emu.grasscutter.net.proto.VectorOuterClass.Vector; import emu.grasscutter.utils.Utils; +import java.io.Serial; import java.io.Serializable; import java.util.List; import lombok.*; import lombok.experimental.Accessors; +@Setter +@Getter @Entity @Accessors(chain = true) public class Position implements Serializable { - private static final long serialVersionUID = -2001232313615923575L; + @Serial private static final long serialVersionUID = -2001232313615923575L; public static final Position ZERO = new Position(0, 0, 0); public static final Position IDENTITY = new Position(0, 0); @@ -21,22 +24,16 @@ public class Position implements Serializable { @SerializedName( value = "x", alternate = {"_x", "X"}) - @Getter - @Setter private float x; @SerializedName( value = "y", alternate = {"_y", "Y"}) - @Getter - @Setter private float y; @SerializedName( value = "z", alternate = {"_z", "Z"}) - @Getter - @Setter private float z; public Position() {} @@ -143,8 +140,8 @@ public Position subtract(Position sub) { /** In radians */ public Position translate(float dist, float angle) { - this.x += dist * Math.sin(angle); - this.y += dist * Math.cos(angle); + this.x += (float) (dist * Math.sin(angle)); + this.y += (float) (dist * Math.cos(angle)); return this; } @@ -173,8 +170,8 @@ public Position nearby2d(float range) { public Position translateWithDegrees(float dist, float angle) { angle = (float) Math.toRadians(angle); - this.x += dist * Math.sin(angle); - this.y += -dist * Math.cos(angle); + this.x += (float) (dist * Math.sin(angle)); + this.y += (float) (-dist * Math.cos(angle)); return this; } diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 98047d1fc25..dca0f35d09d 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -79,7 +79,7 @@ public class Scene { private final List afterLoadedCallbacks = new ArrayList<>(); private final List afterHostInitCallbacks = new ArrayList<>(); - @Getter private GameEntity sceneEntity; + @Getter private final GameEntity sceneEntity; @Getter private final ServerTaskScheduler scheduler; public Scene(World world, SceneData sceneData) { @@ -392,14 +392,15 @@ public void updateEntity(GameEntity entity) { } public void updateEntity(GameEntity entity, VisionType type) { - this.broadcastPacket(new PacketSceneEntityUpdateNotify(Arrays.asList(entity), type)); + this.broadcastPacket( + new PacketSceneEntityUpdateNotify(Collections.singletonList(entity), type)); } private static List> chopped(List list, final int L) { - List> parts = new ArrayList>(); + List> parts = new ArrayList<>(); final int N = list.size(); for (int i = 0; i < N; i += L) { - parts.add(new ArrayList(list.subList(i, Math.min(N, i + L)))); + parts.add(new ArrayList<>(list.subList(i, Math.min(N, i + L)))); } return parts; } @@ -882,12 +883,12 @@ public void checkSpawns() { } } - if (toAdd.size() > 0) { + if (!toAdd.isEmpty()) { toAdd.forEach(this::addEntityDirectly); this.broadcastPacket(new PacketSceneEntityAppearNotify(toAdd, VisionType.VISION_TYPE_BORN)); } - if (toRemove.size() > 0) { + if (!toRemove.isEmpty()) { toRemove.forEach(this::removeEntityDirectly); this.broadcastPacket( new PacketSceneEntityDisappearNotify(toRemove, VisionType.VISION_TYPE_REMOVE)); @@ -1110,7 +1111,7 @@ public void unloadGroup(SceneBlock block, int group_id) { .filter(e -> e != null && (e.getBlockId() == block.id && e.getGroupId() == group_id)) .toList(); - if (toRemove.size() > 0) { + if (!toRemove.isEmpty()) { toRemove.forEach(this::removeEntityDirectly); this.broadcastPacket( new PacketSceneEntityDisappearNotify(toRemove, VisionType.VISION_TYPE_REMOVE)); @@ -1253,7 +1254,7 @@ private List loadNpcForPlayer(Player player) { sceneNpcBornEntries.add(i); }); - if (sceneNpcBornEntries.size() > 0) { + if (!sceneNpcBornEntries.isEmpty()) { this.broadcastPacket(new PacketGroupSuiteNotify(sceneNpcBornEntries)); Grasscutter.getLogger().trace("Loaded Npc Group Suite {}", sceneNpcBornEntries); } diff --git a/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java b/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java index fe443e23429..91d4b4d7101 100644 --- a/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java +++ b/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java @@ -1,12 +1,18 @@ package emu.grasscutter.game.world; -import dev.morphia.annotations.*; +import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Id; +import dev.morphia.annotations.Indexed; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.player.Player; -import emu.grasscutter.scripts.data.*; -import java.util.*; +import emu.grasscutter.scripts.data.SceneGadget; +import emu.grasscutter.scripts.data.SceneGroup; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import lombok.*; +import lombok.Getter; +import lombok.Setter; import org.bson.types.ObjectId; @Entity(value = "group_instances", useDiscriminator = false) @@ -19,11 +25,11 @@ public final class SceneGroupInstance { @Getter private transient SceneGroup luaGroup; @Getter @Setter private int targetSuiteId; @Getter @Setter private int activeSuiteId; - @Getter private Set deadEntities; // Config_ids + @Getter private final Set deadEntities; // Config_ids private boolean isCached; - @Getter private Map cachedGadgetStates; - @Getter private Map cachedVariables; + @Getter private final Map cachedGadgetStates; + @Getter private final Map cachedVariables; @Getter @Setter private int lastTimeRefreshed; @@ -42,7 +48,8 @@ public SceneGroupInstance(SceneGroup group, Player owner) { false; // This is true when the group is not loaded on scene but caches suite data } - @Deprecated // Morphia only! + @Deprecated + // Morphia only! SceneGroupInstance() { this.cachedVariables = new ConcurrentHashMap<>(); this.deadEntities = new HashSet<>(); diff --git a/src/main/java/emu/grasscutter/game/world/SpawnDataEntry.java b/src/main/java/emu/grasscutter/game/world/SpawnDataEntry.java index 27865e1ae54..0c9d3e2cea5 100644 --- a/src/main/java/emu/grasscutter/game/world/SpawnDataEntry.java +++ b/src/main/java/emu/grasscutter/game/world/SpawnDataEntry.java @@ -4,17 +4,18 @@ import java.util.*; import lombok.*; +@Getter public class SpawnDataEntry { - @Getter @Setter private transient SpawnGroupEntry group; - @Getter private int monsterId; - @Getter private int gadgetId; - @Getter private int configId; - @Getter private int level; - @Getter private int poseId; - @Getter private int gatherItemId; - @Getter private int gadgetState; - @Getter private Position pos; - @Getter private Position rot; + @Setter private transient SpawnGroupEntry group; + private int monsterId; + private int gadgetId; + private int configId; + private int level; + private int poseId; + private int gatherItemId; + private int gadgetState; + private Position pos; + private Position rot; public GridBlockId getBlockId() { int scale = GridBlockId.getScale(gadgetId); @@ -25,18 +26,20 @@ public GridBlockId getBlockId() { (int) (pos.getZ() / GameDepot.BLOCK_SIZE[scale])); } + @Getter public static class SpawnGroupEntry { - @Getter private int sceneId; - @Getter private int groupId; - @Getter private int blockId; - @Getter @Setter private List spawns; + private int sceneId; + private int groupId; + private int blockId; + @Setter private List spawns; } + @Getter public static class GridBlockId { - @Getter private int sceneId; - @Getter private int scale; - @Getter private int x; - @Getter private int z; + private final int sceneId; + private final int scale; + private final int x; + private final int z; public GridBlockId(int sceneId, int scale, int x, int z) { this.sceneId = sceneId; diff --git a/src/main/java/emu/grasscutter/game/world/World.java b/src/main/java/emu/grasscutter/game/world/World.java index 434583f6f23..5e5a250b223 100644 --- a/src/main/java/emu/grasscutter/game/world/World.java +++ b/src/main/java/emu/grasscutter/game/world/World.java @@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import lombok.Getter; +import lombok.Setter; import lombok.val; import org.jetbrains.annotations.NotNull; @@ -48,10 +49,10 @@ public class World implements Iterable { @Getter private final List players; @Getter private final Int2ObjectMap scenes; - @Getter private EntityWorld entity; + @Getter private final EntityWorld entity; private int nextEntityId = 0; private int nextPeerId = 0; - private int worldLevel; + @Setter @Getter private int worldLevel; @Getter private boolean isMultiplayer = false; @Getter private boolean timeLocked; @@ -121,14 +122,6 @@ public int getNextPeerId() { return ++this.nextPeerId; } - public int getWorldLevel() { - return worldLevel; - } - - public void setWorldLevel(int worldLevel) { - this.worldLevel = worldLevel; - } - protected synchronized void setHost(Player host) { this.host = host; } @@ -296,7 +289,7 @@ public synchronized void removePlayer(Player player) { scene.removePlayer(player); // Info packet for other players - if (this.getPlayers().size() > 0) { + if (!this.getPlayers().isEmpty()) { this.updatePlayerInfos(player); } diff --git a/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java b/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java index 39bc9371734..b9c4e0dadd0 100644 --- a/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java +++ b/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java @@ -11,10 +11,13 @@ import emu.grasscutter.server.game.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import lombok.Getter; import org.luaj.vm2.LuaError; public class WorldDataSystem extends BaseGameSystem { + @Getter private final Map chestInteractHandlerMap; // chestType-Handler + private final Map sceneInvestigationGroupMap; // public WorldDataSystem(GameServer server) { @@ -44,10 +47,6 @@ public synchronized void loadChestConfig() { } } - public Map getChestInteractHandlerMap() { - return chestInteractHandlerMap; - } - public RewardPreviewData getRewardByBossId(int monsterId) { var investigationMonsterData = GameData.getInvestigationMonsterDataMap().values().parallelStream() diff --git a/src/main/java/emu/grasscutter/net/packet/BasePacket.java b/src/main/java/emu/grasscutter/net/packet/BasePacket.java index bc65ae184b9..1f758a4a5ef 100644 --- a/src/main/java/emu/grasscutter/net/packet/BasePacket.java +++ b/src/main/java/emu/grasscutter/net/packet/BasePacket.java @@ -3,17 +3,19 @@ import com.google.protobuf.GeneratedMessageV3; import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; import java.io.*; +import lombok.Getter; +import lombok.Setter; public class BasePacket { private static final int const1 = 17767; // 0x4567 private static final int const2 = -30293; // 0x89ab - public boolean shouldEncrypt = true; - private int opcode; + public final boolean shouldEncrypt = true; + @Setter @Getter private int opcode; private boolean shouldBuildHeader = false; - private byte[] header; - private byte[] data; + @Setter @Getter private byte[] header; + @Getter private byte[] data; // Encryption - private boolean useDispatchKey; + @Setter private boolean useDispatchKey; public BasePacket(int opcode) { this.opcode = opcode; @@ -29,42 +31,14 @@ public BasePacket(int opcode, boolean buildHeader) { this.shouldBuildHeader = buildHeader; } - public int getOpcode() { - return opcode; - } - - public void setOpcode(int opcode) { - this.opcode = opcode; - } - public boolean useDispatchKey() { return useDispatchKey; } - public void setUseDispatchKey(boolean useDispatchKey) { - this.useDispatchKey = useDispatchKey; - } - - public byte[] getHeader() { - return header; - } - - public void setHeader(byte[] header) { - this.header = header; - } - public boolean shouldBuildHeader() { return shouldBuildHeader; } - public byte[] getData() { - return data; - } - - public void setData(byte[] data) { - this.data = data; - } - public void setData(GeneratedMessageV3 proto) { this.data = proto.toByteArray(); } @@ -74,6 +48,10 @@ public void setData(GeneratedMessageV3.Builder proto) { this.data = proto.build().toByteArray(); } + public void setData(byte[] packet) { + this.data = packet; + } + public BasePacket buildHeader(int clientSequence) { if (this.getHeader() != null && clientSequence == 0) { return this; diff --git a/src/main/java/emu/grasscutter/plugin/Plugin.java b/src/main/java/emu/grasscutter/plugin/Plugin.java index 03f14a824b9..b98b2cc523c 100644 --- a/src/main/java/emu/grasscutter/plugin/Plugin.java +++ b/src/main/java/emu/grasscutter/plugin/Plugin.java @@ -30,7 +30,7 @@ public abstract class Plugin { @SuppressWarnings("unused") private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) { if (this.identifier != null) { - Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt."); + Grasscutter.getLogger().warn("{} had a reinitialization attempt.", this.identifier.name); return; } @@ -45,7 +45,7 @@ private void initializePlugin(PluginIdentifier identifier, URLClassLoader classL if (!this.dataFolder.exists() && !this.dataFolder.mkdirs()) { Grasscutter.getLogger() - .warn("Failed to create plugin data folder for " + this.identifier.name); + .warn("Failed to create plugin data folder for {}", this.identifier.name); } } diff --git a/src/main/java/emu/grasscutter/plugin/PluginManager.java b/src/main/java/emu/grasscutter/plugin/PluginManager.java index 8ca612061aa..b085735c854 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginManager.java +++ b/src/main/java/emu/grasscutter/plugin/PluginManager.java @@ -20,7 +20,7 @@ public final class PluginManager { * A 'breaking change' is something which changes the existing logic of the API. */ @SuppressWarnings("FieldCanBeLocal") - public static int API_VERSION = 2; + public static final int API_VERSION = 2; /* All loaded plugins. */ private final Map plugins = new LinkedHashMap<>(); diff --git a/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java b/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java index 67bc2f02320..af2a9990170 100644 --- a/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java +++ b/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java @@ -9,10 +9,17 @@ import emu.grasscutter.server.scheduler.ServerTaskScheduler; import java.util.*; import java.util.stream.Stream; +import lombok.Getter; /** Hooks into the {@link GameServer} class, adding convenient ways to do certain things. */ public final class ServerHelper { - private static ServerHelper instance; + /** + * -- GETTER -- Gets the server hook instance. + * + * @return A {@link ServerHelper} singleton. + */ + @Getter private static ServerHelper instance; + private final GameServer gameServer; private final HttpServer httpServer; @@ -29,15 +36,6 @@ public ServerHelper(GameServer gameServer, HttpServer httpServer) { instance = this; } - /** - * Gets the server hook instance. - * - * @return A {@link ServerHelper} singleton. - */ - public static ServerHelper getInstance() { - return instance; - } - /** * @return The server's current run mode. */ diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 4e5229600e2..82317bb3db9 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -30,12 +30,13 @@ import java.util.stream.Collectors; import javax.annotation.*; import kotlin.Pair; +import lombok.Getter; import lombok.val; import org.luaj.vm2.*; import org.luaj.vm2.lib.jse.CoerceJavaToLua; public class SceneScriptManager { - private final Scene scene; + @Getter private final Scene scene; private final Map variables; private SceneMeta meta; private boolean isInit; @@ -54,10 +55,10 @@ public class SceneScriptManager { private final Map sceneGroups; private final Map sceneGroupsInstances; private final Map cachedSceneGroupsInstances; - private ScriptMonsterTideService scriptMonsterTideService; - private ScriptMonsterSpawnService scriptMonsterSpawnService; + @Getter private ScriptMonsterTideService scriptMonsterTideService; + @Getter private final ScriptMonsterSpawnService scriptMonsterSpawnService; /** blockid - loaded groupSet */ - private final Map> loadedGroupSetPerBlock; + @Getter private final Map> loadedGroupSetPerBlock; private static final Int2ObjectMap> groupGridsCache = new Int2ObjectOpenHashMap<>(); public static final ExecutorService eventExecutor; @@ -100,10 +101,6 @@ public SceneScriptManager(Scene scene) { new Thread(this::init).start(); } - public Scene getScene() { - return scene; - } - public SceneConfig getConfig() { for (int i = 0; i < 10; ++i) { if (this.isInit) { @@ -270,7 +267,7 @@ public int refreshGroup( // If that trigger has been refreshed, ensure it does not get // deregistered anyway when the trigger completes its invocation. for (var triggerSet : currentTriggers.values()) { - var toSave = new HashSet(triggerSet); + var toSave = new HashSet<>(triggerSet); toSave.retainAll(ongoingTriggers); toSave.forEach(t -> t.setPreserved(true)); } @@ -385,10 +382,6 @@ public synchronized void deregisterRegion(SceneRegion region) { .ifPresent(entityRegion -> this.regions.remove(entityRegion.getId())); } - public Map> getLoadedGroupSetPerBlock() { - return loadedGroupSetPerBlock; - } - // TODO optimize public SceneGroup getGroupById(int groupId) { for (var block : getBlocks().values()) { @@ -678,7 +671,7 @@ public void unregisterGroup(SceneGroup group) { } public void checkRegions() { - if (this.regions.size() == 0) { + if (this.regions.isEmpty()) { return; } @@ -847,13 +840,13 @@ public Future callEvent(int groupId, int eventType) { } public Future callEvent(@Nonnull ScriptArgs params) { - /** - * We use ThreadLocal to trans SceneScriptManager context to ScriptLib, to avoid eval script for - * every groups' trigger in every scene instances. But when callEvent is called in a ScriptLib - * func, it may cause NPE because the inner call cleans the ThreadLocal so that outer call could - * not get it. e.g. CallEvent -> set -> ScriptLib.xxx -> CallEvent -> set -> remove -> NPE -> - * (remove) So we use thread pool to clean the stack to avoid this new issue. - */ + /* + We use ThreadLocal to trans SceneScriptManager context to ScriptLib, to avoid eval script for + every groups' trigger in every scene instances. But when callEvent is called in a ScriptLib + func, it may cause NPE because the inner call cleans the ThreadLocal so that outer call could + not get it. e.g. CallEvent -> set -> ScriptLib.xxx -> CallEvent -> set -> remove -> NPE -> + (remove) So we use thread pool to clean the stack to avoid this new issue. + */ return eventExecutor.submit(() -> this.realCallEvent(params)); } @@ -887,7 +880,7 @@ private void realCallEvent(@Nonnull ScriptArgs params) { } } catch (Throwable throwable) { Grasscutter.getLogger() - .error("Condition Trigger " + params.type + " triggered exception", throwable); + .error("Condition Trigger {} triggered exception", params.type, throwable); } finally { // make sure it is removed ScriptLoader.getScriptLib().removeSceneScriptManager(); @@ -913,7 +906,7 @@ private boolean handleEventForTrigger(ScriptArgs params, SceneTrigger trigger) { return false; } catch (Throwable ex) { Grasscutter.getLogger() - .error("Condition Trigger " + trigger.getName() + " triggered exception", ex); + .error("Condition Trigger {} triggered exception", trigger.getName(), ex); return false; } finally { ScriptLoader.getScriptLib().removeCurrentGroup(); @@ -1009,14 +1002,6 @@ public LuaValue safetyCall(String name, LuaValue func, LuaValue args, SceneGroup } } - public ScriptMonsterTideService getScriptMonsterTideService() { - return scriptMonsterTideService; - } - - public ScriptMonsterSpawnService getScriptMonsterSpawnService() { - return scriptMonsterSpawnService; - } - public EntityGadget createGadget(int groupId, int blockId, SceneGadget g) { return createGadget(groupId, blockId, g, g.state); } diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index e5ce947dffa..2118ea8616f 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -632,9 +632,7 @@ public int DelWorktopOption(int var1) { worktop.removeWorktopOption(callParams.param2); var scene = getSceneScriptManager().getScene(); - Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> { - scene.broadcastPacket(new PacketWorktopOptionNotify(gadget)); - }, 1); + Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> scene.broadcastPacket(new PacketWorktopOptionNotify(gadget)), 1); return 0; } @@ -1999,7 +1997,7 @@ public int DropSubfield(LuaTable table) { logger.debug("[LUA] Call DropSubfield with {}", printTable(table)); String subfield_name = table.get("subfield_name").toString(); var entity = getCurrentEntity(); - if (!entity.isPresent()) return -1; + if (entity.isEmpty()) return -1; entity.get().dropSubfield(subfield_name); diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java index de5e14b5c64..530c38542e4 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java @@ -29,12 +29,13 @@ public class ScriptLoader { @Getter private static ScriptLib scriptLib; @Getter private static LuaValue scriptLibLua; /** suggest GC to remove it if the memory is less */ - private static Map> scriptSources = new ConcurrentHashMap<>(); + private static final Map> scriptSources = new ConcurrentHashMap<>(); - private static Map> scriptsCache = + private static final Map> scriptsCache = new ConcurrentHashMap<>(); /** sceneId - SceneMeta */ - private static Map> sceneMetaCache = new ConcurrentHashMap<>(); + private static final Map> sceneMetaCache = + new ConcurrentHashMap<>(); private static final AtomicReference currentBindings = new AtomicReference<>(null); private static final AtomicReference currentContext = new AtomicReference<>(null); diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java b/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java index 68e1467d0e2..c7fce1d9e71 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneBlock.java @@ -22,15 +22,7 @@ public class SceneBlock { public Map groups; public RTree sceneGroupIndex; - private transient boolean loaded; // Not an actual variable in the scripts either - - public boolean isLoaded() { - return this.loaded; - } - - public void setLoaded(boolean loaded) { - this.loaded = loaded; - } + @Setter @Getter private transient boolean loaded; // Not an actual variable in the scripts either public boolean contains(Position pos) { int range = Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange; @@ -74,8 +66,7 @@ public SceneBlock load(int sceneId, Bindings bindings) { } catch (ScriptException exception) { Grasscutter.getLogger() .error( - "An error occurred while loading block " + this.id + " in scene " + sceneId, - exception); + "An error occurred while loading block {} in scene {}", this.id, sceneId, exception); } Grasscutter.getLogger().trace("Successfully loaded block {} in scene {}.", this.id, sceneId); return this; diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java index 8c8821ca75d..1681cd919fa 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java @@ -24,7 +24,7 @@ public class SceneGadget extends SceneObject { * isOneOff=false, like investigation points, it will disappear temporarily, and appear again in * next big world resource refresh routine. */ - public boolean isOneoff; + @Setter public boolean isOneoff; public int draft_id; public int route_id; @@ -34,8 +34,4 @@ public class SceneGadget extends SceneObject { public int mark_flag; public Explore explore; public int trigger_count; - - public void setIsOneoff(boolean isOneoff) { - this.isOneoff = isOneoff; - } } diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java b/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java index ce84e6fa3dd..a32318f813d 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGroup.java @@ -3,7 +3,6 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.game.world.Position; import emu.grasscutter.scripts.ScriptLoader; -import java.io.*; import java.util.*; import java.util.stream.Collectors; import javax.script.*; @@ -37,9 +36,9 @@ public final class SceneGroup { public SceneReplaceable is_replaceable; /* These are not script variables. */ - private transient boolean loaded; - private transient CompiledScript script; - private transient Bindings bindings; + @Setter @Getter private transient boolean loaded; + @Getter private transient CompiledScript script; + @Getter private transient Bindings bindings; public String overrideScriptPath; public static SceneGroup of(int groupId) { @@ -48,14 +47,6 @@ public static SceneGroup of(int groupId) { return group; } - public boolean isLoaded() { - return this.loaded; - } - - public void setLoaded(boolean loaded) { - this.loaded = loaded; - } - public int getBusinessType() { return this.business == null ? 0 : this.business.type; } @@ -64,10 +55,6 @@ public List getGarbageGadgets() { return this.garbages == null ? null : this.garbages.gadgets; } - public CompiledScript getScript() { - return this.script; - } - public SceneSuite getSuiteByIndex(int index) { if (index < 1 || index > suites.size()) { return null; @@ -75,10 +62,6 @@ public SceneSuite getSuiteByIndex(int index) { return this.suites.get(index - 1); } - public Bindings getBindings() { - return this.bindings; - } - public synchronized SceneGroup load(int sceneId) { if (this.loaded) { return this; @@ -89,7 +72,7 @@ public synchronized SceneGroup load(int sceneId) { this.bindings = ScriptLoader.getEngine().createBindings(); CompiledScript cs; - if (overrideScriptPath != null && !overrideScriptPath.equals("")) { + if (overrideScriptPath != null && !overrideScriptPath.isEmpty()) { cs = ScriptLoader.getScript(overrideScriptPath, true); } else { cs = @@ -168,8 +151,7 @@ public synchronized SceneGroup load(int sceneId) { this.suites.forEach(i -> i.init(this)); } catch (ScriptException e) { Grasscutter.getLogger() - .error( - "An error occurred while loading group " + this.id + " in scene " + sceneId + ".", e); + .error("An error occurred while loading group {} in scene {}.", this.id, sceneId, e); } catch (LuaError luaError) { Grasscutter.getLogger() .error( diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java b/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java index 93038eec21c..abe23d78f3f 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java @@ -29,7 +29,7 @@ public SceneMeta load(int sceneId) { CompiledScript cs = ScriptLoader.getScript("Scene/" + sceneId + "/scene" + sceneId + ".lua"); if (cs == null) { - Grasscutter.getLogger().warn("No script found for scene " + sceneId); + Grasscutter.getLogger().warn("No script found for scene {}", sceneId); return null; } diff --git a/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java b/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java index 9e607861c7f..bf26d170525 100644 --- a/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java +++ b/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java @@ -1,12 +1,13 @@ package emu.grasscutter.scripts.data; +import lombok.Getter; import lombok.ToString; @ToString public class ScriptArgs { - public int param1; - public int param2; - public int param3; + @Getter public int param1; + @Getter public int param2; + @Getter public int param3; public int source_eid; // Source entity public int target_eid; public int group_id; @@ -28,28 +29,16 @@ public ScriptArgs(int groupId, int eventType, int param1, int param2) { this.param2 = param2; } - public int getParam1() { - return param1; - } - public ScriptArgs setParam1(int param1) { this.param1 = param1; return this; } - public int getParam2() { - return param2; - } - public ScriptArgs setParam2(int param2) { this.param2 = param2; return this; } - public int getParam3() { - return param3; - } - public ScriptArgs setParam3(int param3) { this.param3 = param3; return this; diff --git a/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java b/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java index 82b7c2a65fe..5256ae9520a 100644 --- a/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java +++ b/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java @@ -11,8 +11,8 @@ public class EntityController { private static final Set SERVER_CALLED = Set.of("OnBeHurt", "OnDie", "OnTimer"); - private transient CompiledScript entityController; - private transient Bindings entityControllerBindings; + private final transient CompiledScript entityController; + private final transient Bindings entityControllerBindings; public EntityController(CompiledScript entityController, Bindings entityControllerBindings) { this.entityController = entityController; diff --git a/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java b/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java index cc7c445567e..c3839f2e76e 100644 --- a/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java +++ b/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java @@ -239,7 +239,7 @@ public Map cacheType(Class type) { } public String getSetterName(String fieldName) { - if (fieldName == null || fieldName.length() == 0) { + if (fieldName == null || fieldName.isEmpty()) { return null; } if (fieldName.length() == 1) { diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchClient.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchClient.java index 80d943ee8e3..e663d289237 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchClient.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchClient.java @@ -21,11 +21,12 @@ import org.java_websocket.handshake.ServerHandshake; import org.slf4j.Logger; +@Getter public final class DispatchClient extends WebSocketClient implements IDispatcher { - @Getter private final Logger logger = Grasscutter.getLogger(); - @Getter private final Map> handlers = new HashMap<>(); + private final Logger logger = Grasscutter.getLogger(); + private final Map> handlers = new HashMap<>(); - @Getter private final Map>> callbacks = new HashMap<>(); + private final Map>> callbacks = new HashMap<>(); public DispatchClient(URI serverUri) { super(serverUri); diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 0427ede8089..e58309a1df2 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -19,11 +19,12 @@ import org.slf4j.Logger; /* Internal communications server. */ +@Getter public final class DispatchServer extends WebSocketServer implements IDispatcher { - @Getter private final Logger logger = Grasscutter.getLogger(); - @Getter private final Map> handlers = new HashMap<>(); + private final Logger logger = Grasscutter.getLogger(); + private final Map> handlers = new HashMap<>(); - @Getter private final Map>> callbacks = new HashMap<>(); + private final Map>> callbacks = new HashMap<>(); /** * Constructs a new {@code DispatchServer} instance. diff --git a/src/main/java/emu/grasscutter/server/event/EventHandler.java b/src/main/java/emu/grasscutter/server/event/EventHandler.java index c43cfc1a3c8..b47c9121002 100644 --- a/src/main/java/emu/grasscutter/server/event/EventHandler.java +++ b/src/main/java/emu/grasscutter/server/event/EventHandler.java @@ -3,6 +3,7 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.plugin.Plugin; import emu.grasscutter.utils.objects.EventConsumer; +import lombok.Getter; public final class EventHandler { /** @@ -57,7 +58,13 @@ public static void newHandler( private final Class eventClass; private EventConsumer listener; - private HandlerPriority priority; + /** + * -- GETTER -- Returns the handler's priority. + * + * @return The priority of the handler. + */ + @Getter private HandlerPriority priority; + private boolean handleCanceled; private Plugin plugin; @@ -83,15 +90,6 @@ public EventConsumer getCallback() { return this.listener; } - /** - * Returns the handler's priority. - * - * @return The priority of the handler. - */ - public HandlerPriority getPriority() { - return this.priority; - } - /** * Returns if the handler will ignore cancelled events. * diff --git a/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java b/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java index 937f9f8f7c9..b386331dee5 100644 --- a/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java +++ b/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java @@ -1,7 +1,11 @@ package emu.grasscutter.server.event.dispatch; import emu.grasscutter.server.event.types.ServerEvent; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public final class QueryAllRegionsEvent extends ServerEvent { private String regionList; @@ -10,12 +14,4 @@ public QueryAllRegionsEvent(String regionList) { this.regionList = regionList; } - - public String getRegionList() { - return this.regionList; - } - - public void setRegionList(String regionList) { - this.regionList = regionList; - } } diff --git a/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java b/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java index 6ae59362d12..8054cc22382 100644 --- a/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java +++ b/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java @@ -1,7 +1,11 @@ package emu.grasscutter.server.event.dispatch; import emu.grasscutter.server.event.types.ServerEvent; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public final class QueryCurrentRegionEvent extends ServerEvent { private String regionInfo; @@ -10,12 +14,4 @@ public QueryCurrentRegionEvent(String regionInfo) { this.regionInfo = regionInfo; } - - public String getRegionInfo() { - return this.regionInfo; - } - - public void setRegionInfo(String regionInfo) { - this.regionInfo = regionInfo; - } } diff --git a/src/main/java/emu/grasscutter/server/event/entity/EntityCreationEvent.java b/src/main/java/emu/grasscutter/server/event/entity/EntityCreationEvent.java index c59408fdd55..9019d1ca42b 100644 --- a/src/main/java/emu/grasscutter/server/event/entity/EntityCreationEvent.java +++ b/src/main/java/emu/grasscutter/server/event/entity/EntityCreationEvent.java @@ -6,6 +6,8 @@ import lombok.*; /** Invoked when an entity is created. */ +@Setter +@Getter @AllArgsConstructor public final class EntityCreationEvent extends Event { /** @@ -21,9 +23,9 @@ public static T call(Class type, Class[] argTypes, return type.cast(event.getEntity()); } - @Getter @Setter private Class entityType; - @Getter @Setter private Class[] constructorArgTypes; - @Getter @Setter private Object[] constructorArgs; + private Class entityType; + private Class[] constructorArgTypes; + private Object[] constructorArgs; /** * Creates a new entity. Returns null if the entity could not be created. diff --git a/src/main/java/emu/grasscutter/server/event/entity/EntityDamageEvent.java b/src/main/java/emu/grasscutter/server/event/entity/EntityDamageEvent.java index 34527941a4a..8995fe15e04 100644 --- a/src/main/java/emu/grasscutter/server/event/entity/EntityDamageEvent.java +++ b/src/main/java/emu/grasscutter/server/event/entity/EntityDamageEvent.java @@ -7,10 +7,11 @@ import javax.annotation.Nullable; import lombok.*; +@Getter public final class EntityDamageEvent extends EntityEvent implements Cancellable { - @Getter @Setter private float damage; - @Getter @Setter private ElementType attackElementType; - @Getter @Nullable private final GameEntity damager; + @Setter private float damage; + @Setter private ElementType attackElementType; + @Nullable private final GameEntity damager; public EntityDamageEvent( GameEntity entity, diff --git a/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java b/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java index 2f6c3c1dfa1..4a8d4021534 100644 --- a/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java +++ b/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java @@ -6,9 +6,10 @@ import javax.annotation.Nullable; import lombok.Getter; +@Getter public final class EntityDeathEvent extends EntityEvent { - @Getter private final Location deathLocation; - @Getter @Nullable private final GameEntity killer; + private final Location deathLocation; + @Nullable private final GameEntity killer; public EntityDeathEvent(GameEntity entity, int killerId) { super(entity); diff --git a/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java b/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java index 7c0bcc54fba..fedda674d2e 100644 --- a/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java +++ b/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java @@ -4,7 +4,9 @@ import emu.grasscutter.game.world.Position; import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; import emu.grasscutter.server.event.types.EntityEvent; +import lombok.Getter; +@Getter public final class EntityMoveEvent extends EntityEvent { private final Position position, rotation; private final MotionState motionState; @@ -17,16 +19,4 @@ public EntityMoveEvent( this.rotation = rotation; this.motionState = motionState; } - - public Position getPosition() { - return this.position; - } - - public Position getRotation() { - return this.rotation; - } - - public MotionState getMotionState() { - return this.motionState; - } } diff --git a/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java b/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java index 24cf09235d7..e94aca6f4ba 100644 --- a/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java @@ -3,25 +3,16 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.server.event.types.GameEvent; import emu.grasscutter.server.game.GameSession; +import lombok.Getter; +import lombok.Setter; +@Getter public final class PlayerCreationEvent extends GameEvent { private final GameSession session; - private Class playerClass; + @Setter private Class playerClass; public PlayerCreationEvent(GameSession session, Class playerClass) { this.session = session; this.playerClass = playerClass; } - - public GameSession getSession() { - return this.session; - } - - public Class getPlayerClass() { - return this.playerClass; - } - - public void setPlayerClass(Class playerClass) { - this.playerClass = playerClass; - } } diff --git a/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java b/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java index b0c14e2f07b..7080641a1e7 100644 --- a/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java @@ -4,10 +4,12 @@ import emu.grasscutter.server.event.Cancellable; import emu.grasscutter.server.event.types.ServerEvent; import javax.annotation.Nullable; +import lombok.Getter; +import lombok.Setter; public final class ReceiveCommandFeedbackEvent extends ServerEvent implements Cancellable { @Nullable private final Player player; - private String message; + @Setter @Getter private String message; public ReceiveCommandFeedbackEvent(@Nullable Player player, String message) { super(Type.GAME); @@ -16,14 +18,6 @@ public ReceiveCommandFeedbackEvent(@Nullable Player player, String message) { this.message = message; } - public String getMessage() { - return this.message; - } - - public void setMessage(String message) { - this.message = message; - } - @Nullable public Player getPlayer() { return this.player; } diff --git a/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java b/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java index 4f21297cf20..092dab88457 100644 --- a/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java @@ -3,11 +3,14 @@ import emu.grasscutter.server.event.Cancellable; import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.server.game.GameSession; +import lombok.Getter; +import lombok.Setter; +@Getter public final class ReceivePacketEvent extends ServerEvent implements Cancellable { private final GameSession gameSession; private final int packetId; - private byte[] packetData; + @Setter private byte[] packetData; public ReceivePacketEvent(GameSession gameSession, int packetId, byte[] packetData) { super(Type.GAME); @@ -16,20 +19,4 @@ public ReceivePacketEvent(GameSession gameSession, int packetId, byte[] packetDa this.packetId = packetId; this.packetData = packetData; } - - public GameSession getGameSession() { - return this.gameSession; - } - - public int getPacketId() { - return this.packetId; - } - - public byte[] getPacketData() { - return this.packetData; - } - - public void setPacketData(byte[] packetData) { - this.packetData = packetData; - } } diff --git a/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java b/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java index 1155b018b29..2eb711825c6 100644 --- a/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/SceneBlockLoadedEvent.java @@ -6,7 +6,7 @@ @Getter public final class SceneBlockLoadedEvent extends ServerEvent { - private SceneBlock block; + private final SceneBlock block; public SceneBlockLoadedEvent(SceneBlock block) { super(Type.GAME); diff --git a/src/main/java/emu/grasscutter/server/event/game/SceneMetaLoadEvent.java b/src/main/java/emu/grasscutter/server/event/game/SceneMetaLoadEvent.java index 0e5768a00fc..c0ae72ba743 100644 --- a/src/main/java/emu/grasscutter/server/event/game/SceneMetaLoadEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/SceneMetaLoadEvent.java @@ -6,7 +6,7 @@ @Getter public final class SceneMetaLoadEvent extends ServerEvent { - private Scene scene; + private final Scene scene; @Setter private boolean override; public SceneMetaLoadEvent(Scene scene) { diff --git a/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java b/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java index 7a6125ba7c2..cd194a7aaa3 100644 --- a/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java @@ -4,10 +4,13 @@ import emu.grasscutter.server.event.Cancellable; import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.server.game.GameSession; +import lombok.Getter; +import lombok.Setter; +@Getter public final class SendPacketEvent extends ServerEvent implements Cancellable { private final GameSession gameSession; - private BasePacket packet; + @Setter private BasePacket packet; public SendPacketEvent(GameSession gameSession, BasePacket packet) { super(Type.GAME); @@ -15,16 +18,4 @@ public SendPacketEvent(GameSession gameSession, BasePacket packet) { this.gameSession = gameSession; this.packet = packet; } - - public GameSession getGameSession() { - return this.gameSession; - } - - public BasePacket getPacket() { - return this.packet; - } - - public void setPacket(BasePacket packet) { - this.packet = packet; - } } diff --git a/src/main/java/emu/grasscutter/server/event/internal/ServerLogEvent.java b/src/main/java/emu/grasscutter/server/event/internal/ServerLogEvent.java index 911e6d0fced..355e5f18ad2 100644 --- a/src/main/java/emu/grasscutter/server/event/internal/ServerLogEvent.java +++ b/src/main/java/emu/grasscutter/server/event/internal/ServerLogEvent.java @@ -2,7 +2,9 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import emu.grasscutter.server.event.types.ServerEvent; +import lombok.Getter; +@Getter public final class ServerLogEvent extends ServerEvent { private final ILoggingEvent loggingEvent; private final String consoleMessage; @@ -13,12 +15,4 @@ public ServerLogEvent(ILoggingEvent loggingEvent, String consoleMessage) { this.loggingEvent = loggingEvent; this.consoleMessage = consoleMessage; } - - public ILoggingEvent getLoggingEvent() { - return this.loggingEvent; - } - - public String getConsoleMessage() { - return this.consoleMessage; - } } diff --git a/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java b/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java index a5e60d7e480..92c1abac00f 100644 --- a/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java +++ b/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java @@ -2,7 +2,9 @@ import emu.grasscutter.server.event.types.ServerEvent; import java.time.OffsetDateTime; +import lombok.Getter; +@Getter public final class ServerStartEvent extends ServerEvent { private final OffsetDateTime startTime; @@ -11,8 +13,4 @@ public ServerStartEvent(Type type, OffsetDateTime startTime) { this.startTime = startTime; } - - public OffsetDateTime getStartTime() { - return this.startTime; - } } diff --git a/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java b/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java index 2fc6bc6a4b5..0f577a87516 100644 --- a/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java +++ b/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java @@ -2,7 +2,9 @@ import emu.grasscutter.server.event.types.ServerEvent; import java.time.OffsetDateTime; +import lombok.Getter; +@Getter public final class ServerStopEvent extends ServerEvent { private final OffsetDateTime stopTime; @@ -11,8 +13,4 @@ public ServerStopEvent(Type type, OffsetDateTime stopTime) { this.stopTime = stopTime; } - - public OffsetDateTime getStopTime() { - return this.stopTime; - } } diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java index 255d1b28105..54beed1427e 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java @@ -6,8 +6,9 @@ import emu.grasscutter.server.event.types.PlayerEvent; import lombok.Getter; +@Getter public final class PlayerCompleteQuestEvent extends PlayerEvent implements Cancellable { - @Getter private final GameQuest quest; + private final GameQuest quest; public PlayerCompleteQuestEvent(Player player, GameQuest quest) { super(player); diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java index 88c48c25e01..ef040cdaf34 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerEnterAreaEvent.java @@ -4,8 +4,9 @@ import emu.grasscutter.server.event.types.PlayerEvent; import lombok.Getter; +@Getter public final class PlayerEnterAreaEvent extends PlayerEvent { - @Getter private final int areaId, areaType; + private final int areaId, areaType; public PlayerEnterAreaEvent(Player player) { super(player); diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerEnterDungeonEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerEnterDungeonEvent.java index b976e99b1de..4e49272d7c5 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerEnterDungeonEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerEnterDungeonEvent.java @@ -5,8 +5,9 @@ import emu.grasscutter.server.event.types.PlayerEvent; import lombok.Getter; +@Getter public final class PlayerEnterDungeonEvent extends PlayerEvent { - @Getter private final DungeonData dungeon; + private final DungeonData dungeon; public PlayerEnterDungeonEvent(Player player, DungeonData dungeon) { super(player); diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java index d669762a4d7..b62394331c8 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java @@ -5,8 +5,10 @@ import emu.grasscutter.server.event.types.PlayerEvent; import lombok.*; +@Setter +@Getter public final class PlayerForgeItemEvent extends PlayerEvent { - @Getter @Setter private GameItem itemForged; + private GameItem itemForged; public PlayerForgeItemEvent(Player player, GameItem itemForged) { super(player); diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerOpenChestEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerOpenChestEvent.java index e397ff33b3e..c24caccd636 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerOpenChestEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerOpenChestEvent.java @@ -5,10 +5,13 @@ import emu.grasscutter.game.world.ChestReward; import emu.grasscutter.server.event.Cancellable; import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; +import lombok.Setter; +@Getter public final class PlayerOpenChestEvent extends PlayerEvent implements Cancellable { private final GadgetChest chest; - private ChestReward reward; + @Setter private ChestReward reward; public PlayerOpenChestEvent(Player player, GadgetChest chest, ChestReward reward) { super(player); @@ -16,16 +19,4 @@ public PlayerOpenChestEvent(Player player, GadgetChest chest, ChestReward reward this.chest = chest; this.reward = reward; } - - public GadgetChest getChest() { - return this.chest; - } - - public void setReward(ChestReward reward) { - this.reward = reward; - } - - public ChestReward getReward() { - return this.reward; - } } diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java index c008a9783f8..c040bfe4a71 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java @@ -4,7 +4,11 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.server.event.Cancellable; import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public final class PlayerReceiveMailEvent extends PlayerEvent implements Cancellable { private Mail message; @@ -13,12 +17,4 @@ public PlayerReceiveMailEvent(Player player, Mail message) { this.message = message; } - - public Mail getMessage() { - return this.message; - } - - public void setMessage(Mail message) { - this.message = message; - } } diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java index 524d2707849..84f7771d209 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java @@ -9,8 +9,9 @@ * This event is invoked when the ENTIRE TEAM dies. To listen for one player death, use {@link * emu.grasscutter.server.event.entity.EntityDeathEvent}. */ +@Getter public final class PlayerTeamDeathEvent extends PlayerEvent { - @Getter private final EntityAvatar selectedAvatar; + private final EntityAvatar selectedAvatar; public PlayerTeamDeathEvent(Player player, EntityAvatar selectedAvatar) { super(player); diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java index d5482e93f25..e04a14766ff 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java @@ -8,9 +8,10 @@ import lombok.*; /** This event is invoked when the player uses food on an avatar. */ +@Getter public final class PlayerUseFoodEvent extends PlayerEvent implements Cancellable { - @Getter private final EntityAvatar selectedAvatar; - @Getter @Setter private ItemData foodUsed; + private final EntityAvatar selectedAvatar; + @Setter private ItemData foodUsed; public PlayerUseFoodEvent(Player player, ItemData foodUsed, EntityAvatar selectedAvatar) { super(player); diff --git a/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java b/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java index e009612ad2f..51546dd9602 100644 --- a/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java +++ b/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java @@ -2,16 +2,14 @@ import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.server.event.Event; +import lombok.Getter; /** An event that is related to entity interactions. */ +@Getter public abstract class EntityEvent extends Event { protected final GameEntity entity; public EntityEvent(GameEntity entity) { this.entity = entity; } - - public GameEntity getEntity() { - return this.entity; - } } diff --git a/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java b/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java index 2d1a7749220..f59a18e98cd 100644 --- a/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java +++ b/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java @@ -2,16 +2,14 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.server.event.Event; +import lombok.Getter; /** An event that is related to player interactions. */ +@Getter public abstract class PlayerEvent extends Event { protected final Player player; public PlayerEvent(Player player) { this.player = player; } - - public Player getPlayer() { - return this.player; - } } diff --git a/src/main/java/emu/grasscutter/server/game/BaseGameSystem.java b/src/main/java/emu/grasscutter/server/game/BaseGameSystem.java index 3fd3db05ce5..c7e9bbdb61d 100644 --- a/src/main/java/emu/grasscutter/server/game/BaseGameSystem.java +++ b/src/main/java/emu/grasscutter/server/game/BaseGameSystem.java @@ -1,13 +1,12 @@ package emu.grasscutter.server.game; +import lombok.Getter; + +@Getter public abstract class BaseGameSystem { protected final GameServer server; public BaseGameSystem(GameServer server) { this.server = server; } - - public GameServer getServer() { - return this.server; - } } diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index ecd6b142540..7c09a303702 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -184,7 +184,7 @@ public GameServer(InetSocketAddress address) { private static InetSocketAddress getAdapterInetSocketAddress() { InetSocketAddress inetSocketAddress; - if (GAME_INFO.bindAddress.equals("")) { + if (GAME_INFO.bindAddress.isEmpty()) { inetSocketAddress = new InetSocketAddress(GAME_INFO.bindPort); } else { inetSocketAddress = new InetSocketAddress(GAME_INFO.bindAddress, GAME_INFO.bindPort); diff --git a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java index 6d747797bea..13cd482be7b 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java +++ b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java @@ -4,10 +4,14 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerDebugMode; -import emu.grasscutter.net.packet.*; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.packet.PacketOpcodesUtils; import emu.grasscutter.server.event.game.ReceivePacketEvent; import emu.grasscutter.server.game.GameSession.SessionState; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; public final class GameServerPacketHandler { private final Int2ObjectMap handlers; @@ -41,7 +45,7 @@ public void registerHandlers(Class handlerClass) { // Debug Grasscutter.getLogger() - .debug("Registered " + this.handlers.size() + " " + handlerClass.getSimpleName() + "s"); + .debug("Registered {} {}s", this.handlers.size(), handlerClass.getSimpleName()); } public void handle(GameSession session, int opcode, byte[] header, byte[] payload) { @@ -91,11 +95,7 @@ public void handle(GameSession session, int opcode, byte[] header, byte[] payloa if (GAME_INFO.logPackets == ServerDebugMode.MISSING || GAME_INFO.logPackets == ServerDebugMode.ALL) { Grasscutter.getLogger() - .info( - "Unhandled packet (" - + opcode - + "): " - + emu.grasscutter.net.packet.PacketOpcodesUtils.getOpcodeName(opcode)); + .info("Unhandled packet ({}): {}", opcode, PacketOpcodesUtils.getOpcodeName(opcode)); } } } diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index fa0d1a35799..a3ffdf8af17 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -17,7 +17,7 @@ import lombok.*; public class GameSession implements GameSessionManager.KcpChannel { - private final GameServer server; + @Getter private final GameServer server; private GameSessionManager.KcpTunnel tunnel; @Getter @Setter private Account account; @@ -44,10 +44,6 @@ public GameSession(GameServer server) { } } - public GameServer getServer() { - return server; - } - public InetSocketAddress getAddress() { try { return tunnel.getAddress(); @@ -99,7 +95,7 @@ public void replayPacket(int opcode, String name) { public void logPacket(String sendOrRecv, int opcode, byte[] payload) { Grasscutter.getLogger() - .info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")"); + .info("{}: {} ({})", sendOrRecv, PacketOpcodesUtils.getOpcodeName(opcode), opcode); if (GAME_INFO.isShowPacketPayload) System.out.println(Utils.bytesToHex(payload)); } diff --git a/src/main/java/emu/grasscutter/server/game/GameSessionManager.java b/src/main/java/emu/grasscutter/server/game/GameSessionManager.java index 5c6ef77704d..6d8702e6299 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSessionManager.java +++ b/src/main/java/emu/grasscutter/server/game/GameSessionManager.java @@ -12,6 +12,8 @@ public class GameSessionManager { @Getter private static final DefaultEventLoop logicThread = new DefaultEventLoop(); private static final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); + + @Getter private static final KcpListener listener = new KcpListener() { @Override @@ -90,10 +92,6 @@ public void handleClose(Ukcp ukcp) { } }; - public static KcpListener getListener() { - return listener; - } - public interface KcpTunnel { InetSocketAddress getAddress(); diff --git a/src/main/java/emu/grasscutter/server/http/HttpServer.java b/src/main/java/emu/grasscutter/server/http/HttpServer.java index e52e389d4b8..721c811bf03 100644 --- a/src/main/java/emu/grasscutter/server/http/HttpServer.java +++ b/src/main/java/emu/grasscutter/server/http/HttpServer.java @@ -66,8 +66,7 @@ public HttpServer() { this.javalin.exception(Exception.class, (exception, ctx) -> { ctx.status(500).result("Internal server error. %s" .formatted(exception.getMessage())); - Grasscutter.getLogger().debug("Exception thrown: " + - exception.getMessage(), exception); + Grasscutter.getLogger().debug("Exception thrown: {}", exception.getMessage(), exception); }); } diff --git a/src/main/java/emu/grasscutter/server/http/Router.java b/src/main/java/emu/grasscutter/server/http/Router.java index 5c7aa9a68ae..d083bba2c9e 100644 --- a/src/main/java/emu/grasscutter/server/http/Router.java +++ b/src/main/java/emu/grasscutter/server/http/Router.java @@ -17,8 +17,8 @@ public interface Router { * Applies this handler to all endpoint types * * @param javalin A Javalin instance. - * @param path - * @param ctx + * @param path The path to apply the handler to. + * @param ctx The handler to apply. * @return The Javalin instance. */ default Javalin allRoutes(Javalin javalin, String path, Handler ctx) { diff --git a/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java b/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java index 37e30a6a326..be8d4cc8b64 100644 --- a/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java +++ b/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java @@ -22,6 +22,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; +import lombok.Getter; import org.slf4j.Logger; /** Handles requests related to region queries. */ @@ -53,12 +54,12 @@ private void initialize() { var usedNames = new ArrayList(); // List to check for potential naming conflicts. var configuredRegions = new ArrayList<>(DISPATCH_INFO.regions); - if (Grasscutter.getRunMode() != ServerRunMode.HYBRID && configuredRegions.size() == 0) { + if (Grasscutter.getRunMode() != ServerRunMode.HYBRID && configuredRegions.isEmpty()) { Grasscutter.getLogger() .error( "[Dispatch] There are no game servers available. Exiting due to unplayable state."); System.exit(1); - } else if (configuredRegions.size() == 0) + } else if (configuredRegions.isEmpty()) configuredRegions.add( new Region( "os_usa", @@ -321,6 +322,7 @@ private static void queryCurrentRegion(Context ctx) { } /** Region data container. */ + @Getter public static class RegionData { private final QueryCurrRegionHttpRsp regionQuery; private final String base64; @@ -329,14 +331,6 @@ public RegionData(QueryCurrRegionHttpRsp prq, String b64) { this.regionQuery = prq; this.base64 = b64; } - - public QueryCurrRegionHttpRsp getRegionQuery() { - return this.regionQuery; - } - - public String getBase64() { - return this.base64; - } } /** diff --git a/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java b/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java index e4de100e081..5b1f406a425 100644 --- a/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java +++ b/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java @@ -26,7 +26,7 @@ public final class HandbookHandler implements Router { */ public HandbookHandler() { this.handbook = new String(FileUtils.readResource("/html/handbook.html")); - this.serve = HANDBOOK.enable && this.handbook.length() > 0; + this.serve = HANDBOOK.enable && !this.handbook.isEmpty(); var server = HANDBOOK.server; if (this.serve && server.enforced) { diff --git a/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java b/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java index 65b00364de5..fee90c4bdc2 100644 --- a/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java +++ b/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java @@ -18,7 +18,7 @@ public RootRequestHandler() { try { t = Files.readString(templatePath); } catch (IOException ignored) { - Grasscutter.getLogger().warn("File does not exist: " + templatePath); + Grasscutter.getLogger().warn("File does not exist: {}", templatePath); } this.template = t; } diff --git a/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java index edee6909a03..c35703bb1eb 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java @@ -22,7 +22,7 @@ private static void getAnnouncement(Context ctx) { data = FileUtils.readToString(DataLoader.load("GameAnnouncement.json")); } catch (Exception e) { if (e.getClass() == IOException.class) { - Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e); + Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n{}", e); } } } else if (Objects.equals( @@ -31,7 +31,7 @@ private static void getAnnouncement(Context ctx) { data = FileUtils.readToString(DataLoader.load("GameAnnouncementList.json")); } catch (Exception e) { if (e.getClass() == IOException.class) { - Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e); + Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n{}", e); } } } else { @@ -77,7 +77,7 @@ private static void getPageResources(Context ctx) { ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM); ctx.result(filestream.readAllBytes()); } catch (Exception e) { - Grasscutter.getLogger().warn("File does not exist: " + ctx.path()); + Grasscutter.getLogger().warn("File does not exist: {}", ctx.path()); ctx.status(404); } } diff --git a/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java b/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java index c229a1e195a..279f1ab37ad 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java @@ -3,7 +3,7 @@ public class ComboTokenResJson { public String message; public int retcode; - public LoginData data = new LoginData(); + public final LoginData data = new LoginData(); public static class LoginData { public int account_type = 1; diff --git a/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java b/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java index 2edc529e1c3..f7a37c8f2e1 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java +++ b/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java @@ -39,12 +39,13 @@ public void handle(@NotNull Context ctx) throws Exception { .anyMatch(x -> Objects.equals(x, ctx.endpointHandlerPath()))) { Grasscutter.getLogger() .info( + "{}{}", translate( - "messages.dispatch.request", - Utils.address(ctx), - ctx.method(), - ctx.endpointHandlerPath()) - + (DISPATCH_INFO.logRequests == ServerDebugMode.MISSING ? "(MISSING)" : "")); + "messages.dispatch.request", + Utils.address(ctx), + ctx.method(), + ctx.endpointHandlerPath()), + DISPATCH_INFO.logRequests == ServerDebugMode.MISSING ? "(MISSING)" : ""); } ctx.result(response); } diff --git a/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java b/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java index 0557c9c0568..87d63dafb41 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java @@ -3,10 +3,10 @@ public class LoginResultJson { public String message; public int retcode; - public VerifyData data = new VerifyData(); + public final VerifyData data = new VerifyData(); public static class VerifyData { - public VerifyAccountData account = new VerifyAccountData(); + public final VerifyAccountData account = new VerifyAccountData(); public boolean device_grant_required = false; public String realname_operation = "NONE"; public boolean realperson_required = false; diff --git a/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java b/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java index 7e65e0b48ee..5061c001bb1 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java +++ b/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java @@ -17,7 +17,7 @@ private static void getPageResources(String path, Context ctx) { ctx.result(filestream.readAllBytes()); } catch (Exception e) { if (DISPATCH_INFO.logRequests == Grasscutter.ServerDebugMode.MISSING) { - Grasscutter.getLogger().warn("Webstatic File Missing: " + path); + Grasscutter.getLogger().warn("Webstatic File Missing: {}", path); } ctx.status(404); } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java index 05b0c1941d2..0764d4aa2b1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java @@ -48,8 +48,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex return; } - List costs = - new ArrayList(sg.getCostItemList()); // Can this even be null? + List costs = new ArrayList<>(sg.getCostItemList()); // Can this even be null? costs.add(new ItemParamData(202, sg.getScoin())); costs.add(new ItemParamData(201, sg.getHcoin())); costs.add(new ItemParamData(203, sg.getMcoin())); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilitiesInitFinishCombineNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilitiesInitFinishCombineNotify.java index 626f8f097f3..7b794f220fe 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilitiesInitFinishCombineNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilitiesInitFinishCombineNotify.java @@ -26,7 +26,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex player.getClientAbilityInitFinishHandler().addEntry(ability.getForwardType(), ability); } - if (entry.getInvokesList().size() > 0) { + if (!entry.getInvokesList().isEmpty()) { session.getPlayer().getClientAbilityInitFinishHandler().update(session.getPlayer()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java index a9cb1ccdb75..f8c80383bbb 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java @@ -23,7 +23,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex player.getClientAbilityInitFinishHandler().addEntry(entry.getForwardType(), entry); } - if (notif.getInvokesList().size() > 0) { + if (!notif.getInvokesList().isEmpty()) { session.getPlayer().getClientAbilityInitFinishHandler().update(session.getPlayer()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java index 6489b140abe..bcddf02831c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java @@ -130,12 +130,10 @@ private void handleFallOnGround(GameSession session, GameEntity entity, MotionSt long actualDelay = System.currentTimeMillis() - cachedLandingTimeMillisecond; Grasscutter.getLogger() .trace( - "MOTION_FALL_ON_GROUND received after " - + actualDelay - + "/" - + maxDelay - + "ms." - + (actualDelay > maxDelay ? " Discard" : "")); + "MOTION_FALL_ON_GROUND received after {}/{}ms.{}", + actualDelay, + maxDelay, + actualDelay > maxDelay ? " Discard" : ""); if (actualDelay > maxDelay) { return; } @@ -162,19 +160,15 @@ private void handleFallOnGround(GameSession session, GameEntity entity, MotionSt if (damageFactor > 0) { Grasscutter.getLogger() .debug( - currentHP - + "/" - + maxHP - + "\tLandingSpeed: " - + cachedLandingSpeed - + "\tDamageFactor: " - + damageFactor - + "\tDamage: " - + damage - + "\tNewHP: " - + newHP); + "{}/{}\tLandingSpeed: {}\tDamageFactor: {}\tDamage: {}\tNewHP: {}", + currentHP, + maxHP, + cachedLandingSpeed, + damageFactor, + damage, + newHP); } else { - Grasscutter.getLogger().trace(currentHP + "/" + maxHP + "\tLandingSpeed: 0\tNo damage"); + Grasscutter.getLogger().trace("{}/{}\tLandingSpeed: 0\tNo damage", currentHP, maxHP); } entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, newHP); entity diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java index 3a54acc52eb..c267124d8f6 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java @@ -113,7 +113,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex if (req.getKeyId() > 0) { var encryptSeed = session.getEncryptSeed(); try { - var cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + var cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); cipher.init(Cipher.DECRYPT_MODE, Crypto.CUR_SIGNING_KEY); var clientSeedEncrypted = Utils.base64Decode(req.getClientRandKey()); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeKickPlayerReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeKickPlayerReq.java index 6e80b6fb2e0..607992c6911 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeKickPlayerReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeKickPlayerReq.java @@ -17,13 +17,12 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex .filter(player -> player.getUid() == req.getTargetUid()) .findFirst() .ifPresent( - player -> { - success.set( - session - .getServer() - .getHomeWorldMPSystem() - .kickPlayerFromHome(session.getPlayer(), player.getUid())); - }); + player -> + success.set( + session + .getServer() + .getHomeWorldMPSystem() + .kickPlayerFromHome(session.getPlayer(), player.getUid()))); session.send( new PacketHomeKickPlayerRsp( diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java index 3bfd7bd1795..b5fd35a16ed 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java @@ -12,8 +12,8 @@ public class HandlerQueryPathReq extends PacketHandler { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { var req = QueryPathReq.parseFrom(payload); - /** It is not the actual work */ - if (req.getDestinationPosList().size() > 0) { + /* It is not the actual work */ + if (!req.getDestinationPosList().isEmpty()) { session.send(new PacketQueryPathRsp(req)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java index bfeaafd9ab8..133c06cfc2e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java @@ -16,7 +16,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex GameEntity entity = session.getPlayer().getScene().getEntityById(req.getEntityId()); - if (entity == null || !(entity instanceof EntityMonster || entity instanceof EntityAvatar)) { + if (!(entity instanceof EntityMonster || entity instanceof EntityAvatar)) { return; } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java index 4103ca8d4d7..55f9ed0a232 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java @@ -40,24 +40,11 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex private boolean isValidBirthday(int month, int day) { - switch (month) { - case 1: - case 3: - case 5: - case 7: - case 8: - case 10: - case 12: - return day > 0 & day <= 31; - case 4: - case 6: - case 9: - case 11: - return day > 0 && day <= 30; - case 2: - return day > 0 & day <= 29; - } - - return false; + return switch (month) { + case 1, 3, 5, 7, 8, 10, 12 -> day > 0 & day <= 31; + case 4, 6, 9, 11 -> day > 0 && day <= 30; + case 2 -> day > 0 & day <= 29; + default -> false; + }; } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java index 2ceb236539e..107cce89afc 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java @@ -13,7 +13,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex // Auto template SetPlayerNameReq req = SetPlayerNameReq.parseFrom(payload); - if (req.getNickName() != null && req.getNickName().length() > 0) { + if (req.getNickName() != null && !req.getNickName().isEmpty()) { session.getPlayer().setNickname(req.getNickName()); session.send(new PacketSetPlayerNameRsp(session.getPlayer())); } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java index 335d63b99bf..868dd81f7c5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java @@ -13,7 +13,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex // Auto template SetPlayerSignatureReq req = SetPlayerSignatureReq.parseFrom(payload); - if (req.getSignature() != null && req.getSignature().length() > 0) { + if (req.getSignature() != null && !req.getSignature().isEmpty()) { session.getPlayer().setSignature(req.getSignature()); session.send(new PacketSetPlayerSignatureRsp(session.getPlayer())); } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java index 6eaebaaa72d..d820ce47cd6 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java @@ -43,24 +43,20 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex } } case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption - .FRIEND_ENTER_HOME_OPTION_REFUSE_VALUE -> { - session.send( - new PacketTryEnterHomeRsp( - RetcodeOuterClass.Retcode.RET_HOME_HOME_REFUSE_GUEST_ENTER_VALUE, - req.getTargetUid())); - } + .FRIEND_ENTER_HOME_OPTION_REFUSE_VALUE -> session.send( + new PacketTryEnterHomeRsp( + RetcodeOuterClass.Retcode.RET_HOME_HOME_REFUSE_GUEST_ENTER_VALUE, + req.getTargetUid())); case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption - .FRIEND_ENTER_HOME_OPTION_DIRECT_VALUE -> { - session - .getServer() - .getHomeWorldMPSystem() - .enterHome( - session.getPlayer(), - targetPlayer, - req.getTargetPoint(), - req.getIsTransferToSafePoint()); - } + .FRIEND_ENTER_HOME_OPTION_DIRECT_VALUE -> session + .getServer() + .getHomeWorldMPSystem() + .enterHome( + session.getPlayer(), + targetPlayer, + req.getTargetPoint(), + req.getIsTransferToSafePoint()); } return; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java index 08908c5cbbe..e27ee0fe2c1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java @@ -14,16 +14,15 @@ public PacketActivityScheduleInfoNotify(Collection activityC var proto = ActivityScheduleInfoNotifyOuterClass.ActivityScheduleInfoNotify.newBuilder(); activityConfigItemList.forEach( - item -> { - proto.addActivityScheduleList( - ActivityScheduleInfoOuterClass.ActivityScheduleInfo.newBuilder() - .setActivityId(item.getActivityId()) - .setScheduleId(item.getScheduleId()) - .setIsOpen(true) - .setBeginTime(DateHelper.getUnixTime(item.getBeginTime())) - .setEndTime(DateHelper.getUnixTime(item.getEndTime())) - .build()); - }); + item -> + proto.addActivityScheduleList( + ActivityScheduleInfoOuterClass.ActivityScheduleInfo.newBuilder() + .setActivityId(item.getActivityId()) + .setScheduleId(item.getScheduleId()) + .setIsOpen(true) + .setBeginTime(DateHelper.getUnixTime(item.getBeginTime())) + .setEndTime(DateHelper.getUnixTime(item.getEndTime())) + .build())); this.setData(proto); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java index 1ada85f1684..b71c510a7b3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java @@ -22,7 +22,7 @@ public PacketAvatarExpeditionAllDataRsp( .setExpeditionCountLimit(expeditionCountLimit) .putAllExpeditionInfoMap( expeditionInfo.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toProto()))) .build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java index 5067094ad8d..d2718f31d46 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java @@ -14,7 +14,7 @@ public PacketAvatarExpeditionDataNotify(Map expeditionInfo AvatarExpeditionDataNotify.newBuilder() .putAllExpeditionInfoMap( expeditionInfo.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toProto()))) .build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java index 1d65c6bc549..a5679f024d0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java @@ -21,10 +21,7 @@ public PacketBattlePassMissionUpdateNotify(Collection mission var proto = BattlePassMissionUpdateNotify.newBuilder(); - missions.forEach( - mission -> { - proto.addMissionList(mission.toProto()); - }); + missions.forEach(mission -> proto.addMissionList(mission.toProto())); this.setData(proto.build()); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java index 8d1b9a3b12f..255c9ff03e8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java @@ -12,7 +12,7 @@ public PacketClientAbilityInitFinishNotify(List entries) { int entityId = 0; - if (entries.size() > 0) { + if (!entries.isEmpty()) { AbilityInvokeEntry entry = entries.get(0); entityId = entry.getEntityId(); } 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 14e2755a228..4ddc149e6a4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java @@ -93,11 +93,10 @@ public PacketCodexDataFullNotify(Player player) { .getCodex() .getUnlockedReliquarySuitCodex() .forEach( - reliquarySuit -> { - reliquaryData - .addCodexIdList(reliquarySuit) - .addAllHaveViewedList(Collections.singleton(true)); - }); + reliquarySuit -> + reliquaryData + .addCodexIdList(reliquarySuit) + .addAllHaveViewedList(Collections.singleton(true))); CodexDataFullNotify.Builder proto = CodexDataFullNotify.newBuilder() diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java index 6d9537e194a..1b878706347 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java @@ -26,27 +26,24 @@ public PacketCreateVehicleRsp( && ((EntityVehicle) entity).getOwner().equals(player)) .toList(); - previousVehicles.stream() - .forEach( - entity -> { - List vehicleMembers = - ((EntityVehicle) entity).getVehicleMembers().stream().toList(); - - vehicleMembers.stream() - .forEach( - vehicleMember -> { - player - .getScene() - .broadcastPacket( - new PacketVehicleInteractRsp( - ((EntityVehicle) entity), - vehicleMember, - VehicleInteractTypeOuterClass.VehicleInteractType - .VEHICLE_INTERACT_TYPE_OUT)); - }); - - player.getScene().killEntity(entity, 0); - }); + previousVehicles.forEach( + entity -> { + List vehicleMembers = + ((EntityVehicle) entity).getVehicleMembers().stream().toList(); + + vehicleMembers.forEach( + vehicleMember -> + player + .getScene() + .broadcastPacket( + new PacketVehicleInteractRsp( + ((EntityVehicle) entity), + vehicleMember, + VehicleInteractTypeOuterClass.VehicleInteractType + .VEHICLE_INTERACT_TYPE_OUT))); + + player.getScene().killEntity(entity, 0); + }); EntityVehicle vehicle = new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailResultNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailResultNotify.java index 2c6fc2009fa..cda3a804813 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailResultNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailResultNotify.java @@ -23,7 +23,7 @@ public PacketGetAllMailResultNotify(Player player, boolean gifts) { .setPacketNum(1); var inbox = player.getAllMail(); - if (!gifts && inbox.size() > 0) { + if (!gifts && !inbox.isEmpty()) { packet.addAllMailList( inbox.stream() .filter(mail -> mail.stateValue == 1) diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java index ab691f46bcc..c0ad15beb5e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java @@ -15,7 +15,7 @@ public PacketGetOnlinePlayerListRsp(Player session) { GetOnlinePlayerListRsp.Builder proto = GetOnlinePlayerListRsp.newBuilder(); - if (players.size() != 0) { + if (!players.isEmpty()) { for (Player player : players) { if (player.getUid() == session.getUid()) continue; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java index 609376fb158..8d0c1c57b35 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java @@ -12,7 +12,7 @@ public PacketGetScenePointRsp(Player player, int sceneId) { GetScenePointRsp.Builder p = GetScenePointRsp.newBuilder().setSceneId(sceneId); - if (GameData.getScenePointIdList().size() == 0) { + if (GameData.getScenePointIdList().isEmpty()) { for (int i = 1; i < 1000; i++) { p.addUnlockedPointList(i); p.addUnhidePointList(i); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java index 105e1c7dd3a..65513c62054 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java @@ -15,7 +15,7 @@ public class PacketMailChangeNotify extends BasePacket { public PacketMailChangeNotify(Player player, Mail message) { this( player, - new ArrayList() { + new ArrayList<>() { { add(message); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMonsterSummonTagNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMonsterSummonTagNotify.java index fb0ffe46f3d..3eb03886c69 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMonsterSummonTagNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMonsterSummonTagNotify.java @@ -3,7 +3,6 @@ import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.net.packet.*; import emu.grasscutter.net.proto.MonsterSummonTagNotifyOuterClass.MonsterSummonTagNotify; -import java.util.*; public class PacketMonsterSummonTagNotify extends BasePacket { diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java index dca56bf9b9b..47d4124f8c6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java @@ -20,10 +20,9 @@ public PacketPlayerDataNotify(Player player) { player .getProperties() .forEach( - (key, value) -> { - p.putPropMap( - key, PropValue.newBuilder().setType(key).setIval(value).setVal(value).build()); - }); + (key, value) -> + p.putPropMap( + key, PropValue.newBuilder().setType(key).setIval(value).setVal(value).build())); this.setData(p.build()); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java index 600bd1e2f8e..a6138669199 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java @@ -24,10 +24,10 @@ public PacketPlayerWorldSceneInfoListNotify(Player player) { for (int scene : GameData.getSceneDataMap().keySet()) { var worldInfoBuilder = PlayerWorldSceneInfo.newBuilder().setSceneId(scene).setIsLocked(false); - /** Add scene-specific data */ + /* Add scene-specific data */ // Scenetags - if (sceneTags.keySet().contains(scene)) { + if (sceneTags.containsKey(scene)) { worldInfoBuilder.addAllSceneTagIdList( sceneTags.entrySet().stream() .filter(e -> e.getKey().equals(scene)) diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java index aa1ea7bed6a..c1183a935e9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java @@ -29,7 +29,7 @@ public PacketStoreItemDelNotify(Collection items) { StoreItemDelNotify.Builder proto = StoreItemDelNotify.newBuilder().setStoreType(StoreType.STORE_TYPE_PACK); - items.stream().forEach(item -> proto.addGuidList(item.getGuid())); + items.forEach(item -> proto.addGuidList(item.getGuid())); this.setData(proto); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleInteractRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleInteractRsp.java index d97be81c99d..1853b681bbd 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleInteractRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleInteractRsp.java @@ -37,9 +37,9 @@ public PacketVehicleInteractRsp(Player player, int entityId, VehicleInteractType QuestContent.QUEST_CONTENT_ENTER_VEHICLE, ((EntityVehicle) vehicle).getGadgetId()); } - case VEHICLE_INTERACT_TYPE_OUT -> { - ((EntityVehicle) vehicle).getVehicleMembers().remove(vehicleMember); - } + case VEHICLE_INTERACT_TYPE_OUT -> ((EntityVehicle) vehicle) + .getVehicleMembers() + .remove(vehicleMember); default -> {} } } @@ -57,12 +57,8 @@ public PacketVehicleInteractRsp( proto.setMember(vehicleMember); switch (interactType) { - case VEHICLE_INTERACT_TYPE_IN -> { - vehicle.getVehicleMembers().add(vehicleMember); - } - case VEHICLE_INTERACT_TYPE_OUT -> { - vehicle.getVehicleMembers().remove(vehicleMember); - } + case VEHICLE_INTERACT_TYPE_IN -> vehicle.getVehicleMembers().add(vehicleMember); + case VEHICLE_INTERACT_TYPE_OUT -> vehicle.getVehicleMembers().remove(vehicleMember); default -> {} } } diff --git a/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java b/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java index 38e4c2a022c..fca50cfb28e 100644 --- a/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java +++ b/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java @@ -14,8 +14,13 @@ public final class AsyncServerTask implements Runnable { /* Has the task already been started? */ private boolean started = false; + /** + * -- GETTER -- Returns the state of the task. + * + * @return True if the task has finished execution, false otherwise. + */ /* Has the task finished execution? */ - private boolean finished = false; + @Getter private boolean finished = false; /* The result produced in the async task. */ @Nullable private Object result = null; @@ -49,15 +54,6 @@ public boolean hasStarted() { return this.started; } - /** - * Returns the state of the task. - * - * @return True if the task has finished execution, false otherwise. - */ - public boolean isFinished() { - return this.finished; - } - /** Runs the task. */ @Override public void run() { diff --git a/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java b/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java index 4474cc5cb78..6fd7f2f61d7 100644 --- a/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java +++ b/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java @@ -23,7 +23,7 @@ public final class ServerTaskScheduler { */ public void runTasks() { // Skip if there are no tasks. - if (this.tasks.size() == 0) return; + if (this.tasks.isEmpty()) return; // Run all tasks. for (ServerTask task : this.tasks.values()) { diff --git a/src/main/java/emu/grasscutter/task/TaskMap.java b/src/main/java/emu/grasscutter/task/TaskMap.java index f9da26241d6..22f42d616e1 100644 --- a/src/main/java/emu/grasscutter/task/TaskMap.java +++ b/src/main/java/emu/grasscutter/task/TaskMap.java @@ -154,13 +154,12 @@ private void scan() { this.afterReset.put(taskData.taskName(), (TaskHandler) object); } } else { - Grasscutter.getLogger() - .error("Class " + annotated.getName() + " is not a TaskHandler!"); + Grasscutter.getLogger().error("Class {} is not a TaskHandler!", annotated.getName()); } } catch (Exception exception) { Grasscutter.getLogger() .error( - "Failed to register task handler for " + annotated.getSimpleName(), exception); + "Failed to register task handler for {}", annotated.getSimpleName(), exception); } }); try { diff --git a/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java b/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java index 57f574f1b6a..d9ac86513a5 100644 --- a/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java +++ b/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java @@ -14,7 +14,7 @@ triggerName = "AnnouncementTrigger") public final class AnnouncementTask extends TaskHandler { - static Map intervalMap = new ConcurrentHashMap<>(); + static final Map intervalMap = new ConcurrentHashMap<>(); @Override public void onEnable() { diff --git a/src/main/java/emu/grasscutter/tools/Dumpers.java b/src/main/java/emu/grasscutter/tools/Dumpers.java index d3e7b35e5b4..a2157983012 100644 --- a/src/main/java/emu/grasscutter/tools/Dumpers.java +++ b/src/main/java/emu/grasscutter/tools/Dumpers.java @@ -169,7 +169,7 @@ static void dumpItems(String locale) { Language.getTextMapKey(item.getNameTextMapHash()).get(locale), Quality.from(item.getRankLevel()), item.getItemType(), - item.getIcon().length() > 0 ? item.getIcon().substring(3) : ""))); + !item.getIcon().isEmpty() ? item.getIcon().substring(3) : ""))); // Create a new dump with filtered duplicates. var names = new ArrayList(); diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index ea88a5296d8..5cdaaa13fa4 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -54,7 +54,8 @@ public static void createGmHandbooks(boolean message) throws Exception { GameData.getMainQuestDataMap().int2ObjectEntrySet().stream() .collect( Collectors.toMap( - e -> e.getIntKey(), e -> (int) e.getValue().getTitleTextMapHash()))); + Int2ObjectMap.Entry::getIntKey, + e -> (int) e.getValue().getTitleTextMapHash()))); // val questDescs = new // Int2IntRBTreeMap(GameData.getQuestDataMap().int2ObjectEntrySet().stream().collect(Collectors.toMap(e -> (int) e.getIntKey(), e -> (int) e.getValue().getDescTextMapHash()))); @@ -73,7 +74,7 @@ public static void createGmHandbooks(boolean message) throws Exception { var h = new Object() { void newLine(String line) { - handbookBuilders.forEach(b -> b.append(line + "\n")); + handbookBuilders.forEach(b -> b.append(line).append("\n")); } void newSection(String title) { @@ -91,7 +92,7 @@ void newTranslatedLine(String template, TextStrings... textstrings) { j--; // Retry the action. Language.loadTextMaps(true); } - handbookBuilders.get(i).append(s + "\n"); + handbookBuilders.get(i).append(s).append("\n"); } } @@ -99,7 +100,7 @@ void newTranslatedLine(String template, long... hashes) { newTranslatedLine( template, LongStream.of(hashes) - .mapToObj(hash -> getTextMapKey(hash)) + .mapToObj(Language::getTextMapKey) .toArray(TextStrings[]::new)); } }; @@ -127,7 +128,7 @@ void newTranslatedLine(String template, long... hashes) { for (int i = 0; i < TextStrings.NUM_LANGUAGES; i++) { String desc = languages.get(i).get(descKey).replace("\n", "\n\t\t\t\t").replace("\t", " "); - handbookBuilders.get(i).append(label + desc + "\n"); + handbookBuilders.get(i).append(label).append(desc).append("\n"); } } // Avatars @@ -189,12 +190,11 @@ void newTranslatedLine(String template, long... hashes) { achievementDataMap.values().stream() .filter(AchievementData::isUsed) .forEach( - data -> { - h.newTranslatedLine( - padAchievementId.formatted(data.getId()) + "{0} - {1}", - data.getTitleTextMapHash(), - data.getDescTextMapHash()); - }); + data -> + h.newTranslatedLine( + padAchievementId.formatted(data.getId()) + "{0} - {1}", + data.getTitleTextMapHash(), + data.getDescTextMapHash())); // Write txt files for (int i = 0; i < TextStrings.NUM_LANGUAGES; i++) { @@ -316,10 +316,10 @@ public static void generateGachaMappings() { var path = GachaHandler.getGachaMappingsPath(); if (!Files.exists(path)) { try { - Grasscutter.getLogger().debug("Creating default '" + path + "' data"); + Grasscutter.getLogger().debug("Creating default '{}' data", path); Tools.createGachaMappings(path); } catch (Exception exception) { - Grasscutter.getLogger().warn("Failed to create gacha mappings. \n" + exception); + Grasscutter.getLogger().warn("Failed to create gacha mappings. \n{}", exception); } } } @@ -336,7 +336,7 @@ public static void createGachaMappings(Path location) throws IOException { locale)) { // Some locales fallback to en-us, we don't want to redefine en-us with // vietnamese strings sb.append("\t\"%s\": ".formatted(locale)); - sb.append(jsons.get(i).replace("\n", "\n\t") + ",\n"); + sb.append(jsons.get(i).replace("\n", "\n\t")).append(",\n"); } } sb.setLength(sb.length() - 2); // Delete trailing ",\n" @@ -344,7 +344,7 @@ public static void createGachaMappings(Path location) throws IOException { Files.createDirectories(location.getParent()); Files.writeString(location, sb); - Grasscutter.getLogger().debug("Mappings generated to " + location); + Grasscutter.getLogger().debug("Mappings generated to {}", location); } public static List getAvailableLanguage() { @@ -352,14 +352,13 @@ public static List getAvailableLanguage() { try { Files.newDirectoryStream(getResourcePath("TextMap"), "TextMap*.json") .forEach( - path -> { - availableLangList.add( - path.getFileName() - .toString() - .replace("TextMap", "") - .replace(".json", "") - .toLowerCase()); - }); + path -> + availableLangList.add( + path.getFileName() + .toString() + .replace("TextMap", "") + .replace(".json", "") + .toLowerCase())); } catch (IOException e) { Grasscutter.getLogger().error("Failed to get available languages:", e); } diff --git a/src/main/java/emu/grasscutter/utils/Crypto.java b/src/main/java/emu/grasscutter/utils/Crypto.java index 597aa4c4066..b8399b92aee 100644 --- a/src/main/java/emu/grasscutter/utils/Crypto.java +++ b/src/main/java/emu/grasscutter/utils/Crypto.java @@ -19,12 +19,12 @@ public final class Crypto { public static byte[] DISPATCH_SEED; public static byte[] ENCRYPT_KEY; - public static long ENCRYPT_SEED = Long.parseUnsignedLong("11468049314633205968"); + public static final long ENCRYPT_SEED = Long.parseUnsignedLong("11468049314633205968"); public static byte[] ENCRYPT_SEED_BUFFER = new byte[0]; public static PrivateKey CUR_SIGNING_KEY; - public static Map EncryptionKeys = new HashMap<>(); + public static final Map EncryptionKeys = new HashMap<>(); public static void loadKeys() { DISPATCH_KEY = FileUtils.readResource("/keys/dispatchKey.bin"); @@ -100,8 +100,8 @@ public static QueryCurRegionRspJson encryptAndSignRegionData(byte[] regionInfo, if (key_id == null) { throw new Exception("Key ID was not set"); } + Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); - Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, EncryptionKeys.get(Integer.valueOf(key_id))); // Encrypt regionInfo in chunks diff --git a/src/main/java/emu/grasscutter/utils/FileUtils.java b/src/main/java/emu/grasscutter/utils/FileUtils.java index 0b1ab4fd116..eebacc0143a 100644 --- a/src/main/java/emu/grasscutter/utils/FileUtils.java +++ b/src/main/java/emu/grasscutter/utils/FileUtils.java @@ -41,7 +41,7 @@ public final class FileUtils { break; default: Grasscutter.getLogger() - .error("Invalid URI scheme for class resources: " + uri.getScheme()); + .error("Invalid URI scheme for class resources: {}", uri.getScheme()); break; } } catch (URISyntaxException | IOException e) { @@ -49,7 +49,7 @@ public final class FileUtils { Grasscutter.getLogger().error("Failed to load jar?!"); } finally { DATA_DEFAULT_PATH = path; - Grasscutter.getLogger().debug("Setting path for default data: " + path.toAbsolutePath()); + Grasscutter.getLogger().debug("Setting path for default data: {}", path.toAbsolutePath()); } // Setup Resources path @@ -82,7 +82,7 @@ public final class FileUtils { path = excelBinOutput.get().getParent(); if (path == null) path = root; Grasscutter.getLogger() - .debug("Resources will be loaded from \"" + resources + "/" + path + "\""); + .debug("Resources will be loaded from \"" + resources + "/{}\"", path); } else { Grasscutter.getLogger() .error("Failed to find ExcelBinOutput in resources zip \"" + resources + "\""); @@ -176,7 +176,7 @@ public static void write(String dest, byte[] bytes) { try { Files.write(path, bytes); } catch (IOException e) { - Grasscutter.getLogger().warn("Failed to write file: " + dest); + Grasscutter.getLogger().warn("Failed to write file: {}", dest); } } @@ -188,7 +188,7 @@ public static byte[] read(Path path) { try { return Files.readAllBytes(path); } catch (IOException e) { - Grasscutter.getLogger().warn("Failed to read file: " + path); + Grasscutter.getLogger().warn("Failed to read file: {}", path); } return new byte[0]; @@ -202,8 +202,8 @@ public static byte[] readResource(String resourcePath) { try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) { return is.readAllBytes(); } catch (Exception exception) { - Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath); - Grasscutter.getLogger().debug("Failed to load resource: " + resourcePath, exception); + Grasscutter.getLogger().warn("Failed to read resource: {}", resourcePath); + Grasscutter.getLogger().debug("Failed to load resource: {}", resourcePath, exception); } return new byte[0]; @@ -218,7 +218,7 @@ public static void copyResource(String resourcePath, String destination) { byte[] resource = FileUtils.readResource(resourcePath); FileUtils.write(destination, resource); } catch (Exception exception) { - Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception); + Grasscutter.getLogger().warn("Failed to copy resource: {}\n{}", resourcePath, exception); } } diff --git a/src/main/java/emu/grasscutter/utils/JsonAdapters.java b/src/main/java/emu/grasscutter/utils/JsonAdapters.java index a44e46bace4..8f0920027a2 100644 --- a/src/main/java/emu/grasscutter/utils/JsonAdapters.java +++ b/src/main/java/emu/grasscutter/utils/JsonAdapters.java @@ -1,15 +1,23 @@ package emu.grasscutter.utils; -import com.google.gson.*; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.*; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; import emu.grasscutter.data.common.DynamicFloat; -import emu.grasscutter.game.world.*; +import emu.grasscutter.game.world.GridPosition; +import emu.grasscutter.game.world.Position; import it.unimi.dsi.fastutil.floats.FloatArrayList; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import java.io.IOException; import java.lang.reflect.Field; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Objects; import lombok.val; public interface JsonAdapters { diff --git a/src/main/java/emu/grasscutter/utils/StartupArguments.java b/src/main/java/emu/grasscutter/utils/StartupArguments.java index 1aae558bba9..d538c729a88 100644 --- a/src/main/java/emu/grasscutter/utils/StartupArguments.java +++ b/src/main/java/emu/grasscutter/utils/StartupArguments.java @@ -61,13 +61,12 @@ public interface StartupArguments { // Aliases. "-v", StartupArguments::printVersion)); - putAll( - Map.of( - "-debugall", - parameter -> { - StartupArguments.enableDebug("all"); - return false; - })); + put( + "-debugall", + parameter -> { + StartupArguments.enableDebug("all"); + return false; + }); } }; diff --git a/src/main/java/emu/grasscutter/utils/TsvUtils.java b/src/main/java/emu/grasscutter/utils/TsvUtils.java index a61d755482f..5381059e5a4 100644 --- a/src/main/java/emu/grasscutter/utils/TsvUtils.java +++ b/src/main/java/emu/grasscutter/utils/TsvUtils.java @@ -229,11 +229,11 @@ public static List loadTsvToListSetField(Path filename, Class classTyp } catch (Exception e) { Grasscutter.getLogger() .warn( - "Error deserializing an instance of class " - + classType.getCanonicalName()); - Grasscutter.getLogger().warn("At token #" + t + " of #" + m); - Grasscutter.getLogger().warn("Header names are: " + headerNames); - Grasscutter.getLogger().warn("Tokens are: " + tokens); + "Error deserializing an instance of class {}", + classType.getCanonicalName()); + Grasscutter.getLogger().warn("At token #{} of #{}", t, m); + Grasscutter.getLogger().warn("Header names are: {}", headerNames); + Grasscutter.getLogger().warn("Tokens are: {}", tokens); Grasscutter.getLogger().warn("Stacktrace is: ", e); // System.out.println("Error deserializing an instance of class // "+classType.getCanonicalName()); @@ -247,7 +247,7 @@ public static List loadTsvToListSetField(Path filename, Class classTyp }) .toList(); } catch (Exception e) { - Grasscutter.getLogger().error("Error loading file '" + filename + "' - Stacktrace is: ", e); + Grasscutter.getLogger().error("Error loading file '{}' - Stacktrace is: ", filename, e); return null; } } @@ -286,11 +286,11 @@ public static List loadTsjToListSetField(Path filename, Class classTyp } catch (Exception e) { Grasscutter.getLogger() .warn( - "Error deserializing an instance of class " - + classType.getCanonicalName()); - Grasscutter.getLogger().warn("At token #" + t + " of #" + m); - Grasscutter.getLogger().warn("Header names are: " + headerNames); - Grasscutter.getLogger().warn("Tokens are: " + tokens); + "Error deserializing an instance of class {}", + classType.getCanonicalName()); + Grasscutter.getLogger().warn("At token #{} of #{}", t, m); + Grasscutter.getLogger().warn("Header names are: {}", headerNames); + Grasscutter.getLogger().warn("Tokens are: {}", tokens); Grasscutter.getLogger().warn("Stacktrace is: ", e); return null; } @@ -299,16 +299,15 @@ public static List loadTsjToListSetField(Path filename, Class classTyp } catch (NoSuchFileException e) { Grasscutter.getLogger() .error( - "Error loading file '" - + filename - + "' - File does not exist. You are missing resources. Note that this file may exist in JSON, TSV, or TSJ format, any of which are suitable."); + "Error loading file '{}' - File does not exist. You are missing resources. Note that this file may exist in JSON, TSV, or TSJ format, any of which are suitable.", + filename); return null; } catch (IOException e) { - Grasscutter.getLogger().error("Error loading file '" + filename + "' - Stacktrace is: ", e); + Grasscutter.getLogger().error("Error loading file '{}' - Stacktrace is: ", filename, e); return null; } catch (NoSuchMethodException e) { Grasscutter.getLogger() - .error("Error loading file '" + filename + "' - Class is missing NoArgsConstructor"); + .error("Error loading file '{}' - Class is missing NoArgsConstructor", filename); return null; } } @@ -336,7 +335,7 @@ public static List> loadTsjsToListsConstructor(Class classType, P throws Exception { val pair = getAllArgsConstructor(classType); if (pair == null) { - Grasscutter.getLogger().error("No AllArgsContructor found for class: " + classType); + Grasscutter.getLogger().error("No AllArgsContructor found for class: {}", classType); return null; } val constructor = pair.left(); @@ -406,26 +405,25 @@ public static List> loadTsjsToListsConstructor(Class classType, P } catch (Exception e) { Grasscutter.getLogger() .warn( - "Error deserializing an instance of class " - + classType.getCanonicalName() - + " : " - + constructor.getName()); - Grasscutter.getLogger().warn("At token #" + t + " of #" + m); + "Error deserializing an instance of class {} : {}", + classType.getCanonicalName(), + constructor.getName()); + Grasscutter.getLogger().warn("At token #{} of #{}", t, m); Grasscutter.getLogger() - .warn("Arg names are: " + Arrays.toString(conArgNames)); + .warn("Arg names are: {}", Arrays.toString(conArgNames)); Grasscutter.getLogger() - .warn("Arg types are: " + Arrays.toString(argTypes)); + .warn("Arg types are: {}", Arrays.toString(argTypes)); Grasscutter.getLogger() - .warn("Default Args are: " + Arrays.toString(defaultArgs)); - Grasscutter.getLogger().warn("Args are: " + Arrays.toString(args)); - Grasscutter.getLogger().warn("Header names are: " + headerNames); + .warn("Default Args are: {}", Arrays.toString(defaultArgs)); + Grasscutter.getLogger().warn("Args are: {}", Arrays.toString(args)); + Grasscutter.getLogger().warn("Header names are: {}", headerNames); Grasscutter.getLogger() .warn( - "Header types are: " - + IntStream.of(argPositions) - .mapToObj(i -> (i >= 0) ? argTypes[i] : null) - .toList()); - Grasscutter.getLogger().warn("Tokens are: " + tokens); + "Header types are: {}", + IntStream.of(argPositions) + .mapToObj(i -> (i >= 0) ? argTypes[i] : null) + .toList()); + Grasscutter.getLogger().warn("Tokens are: {}", tokens); Grasscutter.getLogger().warn("Stacktrace is: ", e); return null; } @@ -433,7 +431,7 @@ public static List> loadTsjsToListsConstructor(Class classType, P .toList(); } catch (IOException e) { Grasscutter.getLogger() - .error("Error loading file '" + filename + "' - Stacktrace is: ", e); + .error("Error loading file '{}' - Stacktrace is: ", filename, e); return null; } }) @@ -583,14 +581,10 @@ private T toObj(Class objClass, Type objType) { // - "+e); Grasscutter.getLogger() .error( - "Exception while setting field " - + name - + " (" - + field.classType - + ")" - + " for class " - + objClass - + " - ", + "Exception while setting field {} ({}) for class {} - ", + name, + field.classType, + objClass, e); } }); @@ -598,7 +592,7 @@ private T toObj(Class objClass, Type objType) { } catch (Exception e) { // System.out.println("Exception while creating object of class "+objClass+" - "+e); Grasscutter.getLogger() - .error("Exception while creating object of class " + objClass + " - ", e); + .error("Exception while creating object of class {} - ", objClass, e); return null; } } diff --git a/src/main/java/emu/grasscutter/utils/Utils.java b/src/main/java/emu/grasscutter/utils/Utils.java index 435d6d0f16d..5e77294607a 100644 --- a/src/main/java/emu/grasscutter/utils/Utils.java +++ b/src/main/java/emu/grasscutter/utils/Utils.java @@ -69,7 +69,7 @@ public static String toString(InputStream inputStream) throws IOException { public static void logByteArray(byte[] array) { ByteBuf b = Unpooled.wrappedBuffer(array); - Grasscutter.getLogger().info("\n" + ByteBufUtil.prettyHexDump(b)); + Grasscutter.getLogger().info("\n{}", ByteBufUtil.prettyHexDump(b)); b.release(); } @@ -143,7 +143,7 @@ public static boolean createFolder(String path) { public static boolean copyFromResources(String resource, String destination) { try (InputStream stream = Grasscutter.class.getResourceAsStream(resource)) { if (stream == null) { - Grasscutter.getLogger().warn("Could not find resource: " + resource); + Grasscutter.getLogger().warn("Could not find resource: {}", resource); return false; } @@ -151,7 +151,7 @@ public static boolean copyFromResources(String resource, String destination) { return true; } catch (Exception exception) { Grasscutter.getLogger() - .warn("Unable to copy resource " + resource + " to " + destination, exception); + .warn("Unable to copy resource {} to {}", resource, destination, exception); return false; } } diff --git a/src/main/java/emu/grasscutter/utils/algorithms/KahnsSort.java b/src/main/java/emu/grasscutter/utils/algorithms/KahnsSort.java index 38dee3c5982..c7bc42a80eb 100644 --- a/src/main/java/emu/grasscutter/utils/algorithms/KahnsSort.java +++ b/src/main/java/emu/grasscutter/utils/algorithms/KahnsSort.java @@ -4,7 +4,8 @@ public class KahnsSort { public static class Node { - int source, dest; // Dest is a value, and source too + final int source; + final int dest; // Dest is a value, and source too public Node(int source, int dest) { this.source = source; @@ -13,19 +14,19 @@ public Node(int source, int dest) { } public static class Graph { - Map> mainList; - Map degreeList; + final Map> mainList; + final Map degreeList; - List nodeList; + final List nodeList; public Graph(List nodes, List nodeList) { mainList = new HashMap<>(); this.nodeList = nodeList; - for (int i = 0; i < nodeList.size(); i++) mainList.put(nodeList.get(i), new ArrayList<>()); + for (Integer value : nodeList) mainList.put(value, new ArrayList<>()); degreeList = new HashMap<>(); - for (int i = 0; i < nodeList.size(); i++) degreeList.put(nodeList.get(i), 0); + for (Integer integer : nodeList) degreeList.put(integer, 0); for (Node node : nodes) { mainList.get(node.source).add(node.dest); @@ -56,8 +57,7 @@ public static List doSort(Graph graph) { } } - if (degreeList.values().stream().filter(value -> value != 0).count() != 0) - return null; // Loop found + if (degreeList.values().stream().anyMatch(value -> value != 0)) return null; // Loop found return orderedList; } diff --git a/src/main/java/emu/grasscutter/utils/lang/Language.java b/src/main/java/emu/grasscutter/utils/lang/Language.java index 25bf8bdbd26..5c3b1c968a1 100644 --- a/src/main/java/emu/grasscutter/utils/lang/Language.java +++ b/src/main/java/emu/grasscutter/utils/lang/Language.java @@ -19,6 +19,7 @@ import java.util.regex.*; import java.util.stream.*; import lombok.EqualsAndHashCode; +import lombok.Getter; public final class Language { private static final Map cachedLanguages = new ConcurrentHashMap<>(); @@ -28,7 +29,9 @@ public final class Language { private static boolean scannedTextmaps = false; // Ensure that we don't infinitely rescan on cache misses that don't exist private static Int2ObjectMap textMapStrings; - private final String languageCode; + /** -- GETTER -- get language code */ + @Getter private final String languageCode; + private final Map translations = new ConcurrentHashMap<>(); /** Reads a file and creates a language instance. */ @@ -44,7 +47,7 @@ private Language(LanguageStreamDescription description) { .forEach(entry -> putFlattenedKey(translations, entry.getKey(), entry.getValue())); } catch (Exception exception) { Grasscutter.getLogger() - .warn("Failed to load language file: " + description.getLanguageCode(), exception); + .warn("Failed to load language file: {}", description.getLanguageCode(), exception); } } @@ -99,7 +102,7 @@ public static String translate(String key, Object... args) { try { return translated.formatted(args); } catch (Exception exception) { - Grasscutter.getLogger().error("Failed to format string: " + key, exception); + Grasscutter.getLogger().error("Failed to format string: {}", key, exception); return translated; } } @@ -134,7 +137,7 @@ public static String translate(Locale locale, String key, Object... args) { try { return translated.formatted(args); } catch (Exception exception) { - Grasscutter.getLogger().error("Failed to format string: " + key, exception); + Grasscutter.getLogger().error("Failed to format string: {}", key, exception); return translated; } } @@ -194,7 +197,7 @@ private static LanguageStreamDescription getLanguageFileDescription( if (file == null) { // Provided fallback language. Grasscutter.getLogger() - .warn("Failed to load language file: " + fileName + ", falling back to: " + fallback); + .warn("Failed to load language file: {}, falling back to: {}", fileName, fallback); actualLanguageCode = fallbackLanguageCode; if (cachedLanguages.containsKey(actualLanguageCode)) { return new LanguageStreamDescription(actualLanguageCode, null); @@ -205,7 +208,7 @@ private static LanguageStreamDescription getLanguageFileDescription( if (file == null) { // Fallback the fallback language. Grasscutter.getLogger() - .warn("Failed to load language file: " + fallback + ", falling back to: en-US.json"); + .warn("Failed to load language file: {}, falling back to: en-US.json", fallback); actualLanguageCode = "en-US"; if (cachedLanguages.containsKey(actualLanguageCode)) { return new LanguageStreamDescription(actualLanguageCode, null); @@ -241,7 +244,7 @@ private static Int2ObjectMap loadTextMapFile(String language, IntSet nam m -> (int) Long.parseLong(m.group(1)), m -> m.group(2).replace("\\\"", "\"")))); } catch (Exception e) { - Grasscutter.getLogger().error("Error loading textmap: " + language); + Grasscutter.getLogger().error("Error loading textmap: {}", language); Grasscutter.getLogger().error(e.toString()); } return output; @@ -253,15 +256,12 @@ private static Int2ObjectMap loadTextMapFiles(IntSet nameHashes) { TextStrings.LIST_LANGUAGES.parallelStream() .collect( Collectors.toConcurrentMap( - s -> TextStrings.MAP_LANGUAGES.getInt(s), - s -> loadTextMapFile(s, nameHashes))); + TextStrings.MAP_LANGUAGES::getInt, s -> loadTextMapFile(s, nameHashes))); List> languageMaps = - IntStream.range(0, TextStrings.NUM_LANGUAGES) - .mapToObj(i -> mapLanguageMaps.get(i)) - .collect(Collectors.toList()); + IntStream.range(0, TextStrings.NUM_LANGUAGES).mapToObj(mapLanguageMaps::get).toList(); Map canonicalTextStrings = new HashMap<>(); - return new Int2ObjectOpenHashMap( + return new Int2ObjectOpenHashMap<>( nameHashes .intStream() .boxed() @@ -341,7 +341,7 @@ public static void loadTextMaps(boolean bypassCache) { return Files.getLastModifiedTime(path).toMillis(); } catch (Exception ignored) { Grasscutter.getLogger() - .debug("Exception while checking modified time: ", path); + .debug("Exception while checking modified time: {}", path); return Long.MAX_VALUE; // Don't use cache, something has gone wrong } }) @@ -361,7 +361,7 @@ public static void loadTextMaps(boolean bypassCache) { } catch (NoSuchFileException ignored) { // Cache doesn't exist, generate it. } catch (Exception exception) { - Grasscutter.getLogger().error("Error loading textmaps cache: " + exception.toString()); + Grasscutter.getLogger().error("Error loading textmaps cache: {}", exception); } // Regenerate cache @@ -406,11 +406,6 @@ public static void loadTextMaps(boolean bypassCache) { } } - /** get language code */ - public String getLanguageCode() { - return languageCode; - } - /** * Returns the value (as a string) from a nested key. * diff --git a/src/main/java/emu/grasscutter/utils/objects/ServerLogEventAppender.java b/src/main/java/emu/grasscutter/utils/objects/ServerLogEventAppender.java index 05a89f1704b..3ac2e49f825 100644 --- a/src/main/java/emu/grasscutter/utils/objects/ServerLogEventAppender.java +++ b/src/main/java/emu/grasscutter/utils/objects/ServerLogEventAppender.java @@ -5,9 +5,13 @@ import ch.qos.logback.core.encoder.Encoder; import emu.grasscutter.server.event.internal.ServerLogEvent; import java.nio.charset.StandardCharsets; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public final class ServerLogEventAppender extends AppenderBase { - protected Encoder encoder; + private Encoder encoder; @Override protected void append(E event) { @@ -16,12 +20,4 @@ protected void append(E event) { new ServerLogEvent((ILoggingEvent) event, new String(byteArray, StandardCharsets.UTF_8)); sle.call(); } - - public Encoder getEncoder() { - return this.encoder; - } - - public void setEncoder(Encoder encoder) { - this.encoder = encoder; - } } diff --git a/src/main/java/emu/grasscutter/utils/objects/WeightedList.java b/src/main/java/emu/grasscutter/utils/objects/WeightedList.java index bc9ac658e37..9d822378ff2 100644 --- a/src/main/java/emu/grasscutter/utils/objects/WeightedList.java +++ b/src/main/java/emu/grasscutter/utils/objects/WeightedList.java @@ -4,7 +4,7 @@ import java.util.concurrent.ThreadLocalRandom; public class WeightedList { - private final NavigableMap map = new TreeMap(); + private final NavigableMap map = new TreeMap<>(); private double total = 0; public WeightedList() {}