From 77e246213fd6e684ad7f2f6b1f7b8b1df5d1ab92 Mon Sep 17 00:00:00 2001 From: "Breno A." Date: Sun, 9 Jun 2024 09:33:59 -0300 Subject: [PATCH] refactor: fix javadoc issues --- .../java/emu/grasscutter/data/DataLoader.java | 60 +++++++++---------- .../java/emu/grasscutter/data/GameData.java | 4 +- .../ActivityConditionBaseHandler.java | 2 +- .../grasscutter/game/entity/EntityRegion.java | 2 +- .../stamina/BeforeUpdateStaminaListener.java | 4 +- .../game/player/PlayerProgressManager.java | 6 +- .../scripts/SceneScriptManager.java | 12 ++-- .../emu/grasscutter/server/http/Router.java | 4 +- .../packet/recv/HandlerQueryPathReq.java | 2 +- .../PacketPlayerWorldSceneInfoListNotify.java | 2 +- 10 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/DataLoader.java b/src/main/java/emu/grasscutter/data/DataLoader.java index e6ea19068..0b205181f 100644 --- a/src/main/java/emu/grasscutter/data/DataLoader.java +++ b/src/main/java/emu/grasscutter/data/DataLoader.java @@ -1,12 +1,20 @@ 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 lombok.val; +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; + public class DataLoader { /** @@ -15,7 +23,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,44 +32,37 @@ public class DataLoader { /** * 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); } /** * Load a data file by its name. * * @param resourcePath The path to the data file to be loaded. - * @param useFallback If the file does not exist in the /data directory, should it use the default - * file in the jar? + * @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 { - Path path = - useFallback ? FileUtils.getDataPath(resourcePath) : FileUtils.getDataUserPath(resourcePath); + public static InputStream load(String resourcePath, boolean useFallback) throws FileNotFoundException { + Path path = useFallback ? FileUtils.getDataPath(resourcePath) : FileUtils.getDataUserPath(resourcePath); if (Files.exists(path)) { // Data is in the resource directory try { return Files.newInputStream(path); } catch (IOException e) { - throw new FileNotFoundException( - e.getMessage()); // This is evil but so is changing the function signature at this point + throw new FileNotFoundException(e.getMessage()); // This is evil but so is changing the function signature at this point } } return null; @@ -79,15 +80,13 @@ public class DataLoader { } } - public static Map loadMap( - String resourcePath, Class keyType, Class valueType) throws IOException { + public static Map loadMap(String resourcePath, Class keyType, Class valueType) throws IOException { try (InputStreamReader reader = loadReader(resourcePath)) { return JsonUtils.loadToMap(reader, keyType, valueType); } } - public static List loadTableToList(String resourcePath, Class classType) - throws IOException { + public static List loadTableToList(String resourcePath, Class classType) throws IOException { val path = FileUtils.getDataPathTsjJsonTsv(resourcePath); Grasscutter.getLogger().trace("Loading data table from: " + path); return switch (FileUtils.getFileExtension(path)) { @@ -120,8 +119,7 @@ public class DataLoader { 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"); 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 f6d9a48d7..c2ba581f9 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -713,8 +713,8 @@ public final class GameData { /** * 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/game/activity/condition/ActivityConditionBaseHandler.java b/src/main/java/emu/grasscutter/game/activity/condition/ActivityConditionBaseHandler.java index abf45b02d..2bc47d43f 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/entity/EntityRegion.java b/src/main/java/emu/grasscutter/game/entity/EntityRegion.java index 37be6f3b9..33bfb7050 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 class EntityRegion extends GameEntity { @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/managers/stamina/BeforeUpdateStaminaListener.java b/src/main/java/emu/grasscutter/game/managers/stamina/BeforeUpdateStaminaListener.java index 725ec1880..967d20e01 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/player/PlayerProgressManager.java b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java index 7dfa50d48..b93968f94 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 @@ import java.util.stream.Collectors; // @Entity public final class PlayerProgressManager extends BasePlayerDataManager { /****************************************************************************************************************** - ****************************************************************************************************************** + *

* OPEN STATES ****************************************************************************************************************** *****************************************************************************************************************/ @@ -215,7 +215,7 @@ public final class PlayerProgressManager extends BasePlayerDataManager { } /****************************************************************************************************************** - ****************************************************************************************************************** + *

* MAP AREAS AND POINTS ****************************************************************************************************************** *****************************************************************************************************************/ @@ -313,7 +313,7 @@ public final class PlayerProgressManager extends BasePlayerDataManager { } /****************************************************************************************************************** - ****************************************************************************************************************** + *

* SCENETAGS ****************************************************************************************************************** *****************************************************************************************************************/ diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 106c79483..343783450 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -847,12 +847,12 @@ public class SceneScriptManager { } 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)); } diff --git a/src/main/java/emu/grasscutter/server/http/Router.java b/src/main/java/emu/grasscutter/server/http/Router.java index 5c7aa9a68..d083bba2c 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/packet/recv/HandlerQueryPathReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java index 6b4efa4be..b5fd35a16 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java @@ -12,7 +12,7 @@ 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 */ + /* 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/send/PacketPlayerWorldSceneInfoListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java index 600bd1e2f..dd7d0be1e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java @@ -24,7 +24,7 @@ public class PacketPlayerWorldSceneInfoListNotify extends BasePacket { 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)) {