refactor: fix javadoc issues

This commit is contained in:
Breno A. 2024-06-09 09:33:59 -03:00
parent c9b42a6dfb
commit 77e246213f
10 changed files with 48 additions and 50 deletions

View File

@ -1,12 +1,20 @@
package emu.grasscutter.data; package emu.grasscutter.data;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.utils.*; import emu.grasscutter.utils.FileUtils;
import java.io.*; import emu.grasscutter.utils.JsonUtils;
import java.nio.file.*; import emu.grasscutter.utils.TsvUtils;
import java.util.*;
import lombok.val; 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 { public class DataLoader {
/** /**
@ -15,7 +23,7 @@ public class DataLoader {
* *
* @param resourcePath The path to the data file to be loaded. * @param resourcePath The path to the data file to be loaded.
* @return InputStream of the data file. * @return InputStream of the data file.
* @throws FileNotFoundException * @throws FileNotFoundException If the file is not found.
* @see #load(String, boolean) * @see #load(String, boolean)
*/ */
public static InputStream load(String resourcePath) throws FileNotFoundException { 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 * 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. * @param resourcePath The path to the data file to be loaded.
* @return InputStreamReader of the data file. * @return InputStreamReader of the data file.
* @throws IOException * @throws IOException If the file is not found.
* @throws FileNotFoundException * @throws FileNotFoundException If the file is not found.
* @see #load(String, boolean) * @see #load(String, boolean)
*/ */
public static InputStreamReader loadReader(String resourcePath) public static InputStreamReader loadReader(String resourcePath) throws IOException {
throws IOException, FileNotFoundException { InputStream is = load(resourcePath, true);
try { if (is == null) throw new FileNotFoundException("File not found: " + resourcePath);
InputStream is = load(resourcePath, true); return new InputStreamReader(is);
return new InputStreamReader(is);
} catch (FileNotFoundException exception) {
throw exception;
}
} }
/** /**
* Load a data file by its name. * Load a data file by its name.
* *
* @param resourcePath The path to the data file to be loaded. * @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 * @param useFallback If the file does not exist in the /data directory, should it use the default
* file in the jar? * file in the jar?
* @return InputStream of the data file. * @return InputStream of the data file.
* @throws FileNotFoundException * @throws FileNotFoundException If the file is not found.
*/ */
public static InputStream load(String resourcePath, boolean useFallback) public static InputStream load(String resourcePath, boolean useFallback) throws FileNotFoundException {
throws FileNotFoundException { Path path = useFallback ? FileUtils.getDataPath(resourcePath) : FileUtils.getDataUserPath(resourcePath);
Path path =
useFallback ? FileUtils.getDataPath(resourcePath) : FileUtils.getDataUserPath(resourcePath);
if (Files.exists(path)) { if (Files.exists(path)) {
// Data is in the resource directory // Data is in the resource directory
try { try {
return Files.newInputStream(path); return Files.newInputStream(path);
} catch (IOException e) { } catch (IOException e) {
throw new FileNotFoundException( throw new FileNotFoundException(e.getMessage()); // This is evil but so is changing the function signature at this point
e.getMessage()); // This is evil but so is changing the function signature at this point
} }
} }
return null; return null;
@ -79,15 +80,13 @@ public class DataLoader {
} }
} }
public static <T1, T2> Map<T1, T2> loadMap( public static <T1, T2> Map<T1, T2> loadMap(String resourcePath, Class<T1> keyType, Class<T2> valueType) throws IOException {
String resourcePath, Class<T1> keyType, Class<T2> valueType) throws IOException {
try (InputStreamReader reader = loadReader(resourcePath)) { try (InputStreamReader reader = loadReader(resourcePath)) {
return JsonUtils.loadToMap(reader, keyType, valueType); return JsonUtils.loadToMap(reader, keyType, valueType);
} }
} }
public static <T> List<T> loadTableToList(String resourcePath, Class<T> classType) public static <T> List<T> loadTableToList(String resourcePath, Class<T> classType) throws IOException {
throws IOException {
val path = FileUtils.getDataPathTsjJsonTsv(resourcePath); 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)) { return switch (FileUtils.getFileExtension(path)) {
@ -120,8 +119,7 @@ public class DataLoader {
if (!Files.exists(filePath)) { if (!Files.exists(filePath)) {
var root = filePath.getParent(); var root = filePath.getParent();
if (root.toFile().mkdirs()) if (root.toFile().mkdirs()) Grasscutter.getLogger().info("Created data folder '" + root + "'");
Grasscutter.getLogger().info("Created data folder '" + root + "'");
Grasscutter.getLogger().debug("Creating default '" + name + "' data"); Grasscutter.getLogger().debug("Creating default '" + name + "' data");
FileUtils.copyResource("/defaults/data/" + name, filePath.toString()); FileUtils.copyResource("/defaults/data/" + name, filePath.toString());

View File

@ -713,8 +713,8 @@ public final class GameData {
/** /**
* Fetches the trial data * Fetches the trial data
* *
* @param trialAvatarIndexId * @param trialAvatarIndexId The ID of the trial avatar
* @return * @return The trial data for the trial avatar
*/ */
@Nullable public static TrialAvatarActivityDataData getTrialAvatarActivityDataByAvatarIndex( @Nullable public static TrialAvatarActivityDataData getTrialAvatarActivityDataByAvatarIndex(
int trialAvatarIndexId) { int trialAvatarIndexId) {

View File

@ -13,7 +13,7 @@ public abstract class ActivityConditionBaseHandler {
* Execute activity condition handler and return result of it's calculation * Execute activity condition handler and return result of it's calculation
* *
* @param activityData {@link PlayerActivityData} object containing info about activity * @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 * @param params params for handler
* @return result of condition calculation * @return result of condition calculation
*/ */

View File

@ -82,7 +82,7 @@ public class EntityRegion extends GameEntity {
@Override @Override
public SceneEntityInfoOuterClass.SceneEntityInfo toProto() { public SceneEntityInfoOuterClass.SceneEntityInfo toProto() {
/** The Region Entity would not be sent to client. */ /* The Region Entity would not be sent to client. */
return null; return null;
} }

View File

@ -7,7 +7,7 @@ public interface BeforeUpdateStaminaListener {
* *
* @param reason Why updating stamina. * @param reason Why updating stamina.
* @param newStamina New ABSOLUTE stamina value. * @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); int onBeforeUpdateStamina(String reason, int newStamina, boolean isCharacterStamina);
@ -17,7 +17,7 @@ public interface BeforeUpdateStaminaListener {
* *
* @param reason Why updating stamina. * @param reason Why updating stamina.
* @param consumption ConsumptionType and RELATIVE stamina change amount. * @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( Consumption onBeforeUpdateStamina(
String reason, Consumption consumption, boolean isCharacterStamina); String reason, Consumption consumption, boolean isCharacterStamina);

View File

@ -19,7 +19,7 @@ import java.util.stream.Collectors;
// @Entity // @Entity
public final class PlayerProgressManager extends BasePlayerDataManager { public final class PlayerProgressManager extends BasePlayerDataManager {
/****************************************************************************************************************** /******************************************************************************************************************
****************************************************************************************************************** * <p>
* OPEN STATES * OPEN STATES
****************************************************************************************************************** ******************************************************************************************************************
*****************************************************************************************************************/ *****************************************************************************************************************/
@ -215,7 +215,7 @@ public final class PlayerProgressManager extends BasePlayerDataManager {
} }
/****************************************************************************************************************** /******************************************************************************************************************
****************************************************************************************************************** * <p>
* MAP AREAS AND POINTS * MAP AREAS AND POINTS
****************************************************************************************************************** ******************************************************************************************************************
*****************************************************************************************************************/ *****************************************************************************************************************/
@ -313,7 +313,7 @@ public final class PlayerProgressManager extends BasePlayerDataManager {
} }
/****************************************************************************************************************** /******************************************************************************************************************
****************************************************************************************************************** * <p>
* SCENETAGS * SCENETAGS
****************************************************************************************************************** ******************************************************************************************************************
*****************************************************************************************************************/ *****************************************************************************************************************/

View File

@ -847,12 +847,12 @@ public class SceneScriptManager {
} }
public Future<?> callEvent(@Nonnull ScriptArgs params) { public Future<?> callEvent(@Nonnull ScriptArgs params) {
/** /*
* We use ThreadLocal to trans SceneScriptManager context to ScriptLib, to avoid eval script for 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 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 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 -> 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. (remove) So we use thread pool to clean the stack to avoid this new issue.
*/ */
return eventExecutor.submit(() -> this.realCallEvent(params)); return eventExecutor.submit(() -> this.realCallEvent(params));
} }

View File

@ -17,8 +17,8 @@ public interface Router {
* Applies this handler to all endpoint types * Applies this handler to all endpoint types
* *
* @param javalin A Javalin instance. * @param javalin A Javalin instance.
* @param path * @param path The path to apply the handler to.
* @param ctx * @param ctx The handler to apply.
* @return The Javalin instance. * @return The Javalin instance.
*/ */
default Javalin allRoutes(Javalin javalin, String path, Handler ctx) { default Javalin allRoutes(Javalin javalin, String path, Handler ctx) {

View File

@ -12,7 +12,7 @@ public class HandlerQueryPathReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = QueryPathReq.parseFrom(payload); var req = QueryPathReq.parseFrom(payload);
/** It is not the actual work */ /* It is not the actual work */
if (!req.getDestinationPosList().isEmpty()) { if (!req.getDestinationPosList().isEmpty()) {
session.send(new PacketQueryPathRsp(req)); session.send(new PacketQueryPathRsp(req));
} }

View File

@ -24,7 +24,7 @@ public class PacketPlayerWorldSceneInfoListNotify extends BasePacket {
for (int scene : GameData.getSceneDataMap().keySet()) { for (int scene : GameData.getSceneDataMap().keySet()) {
var worldInfoBuilder = PlayerWorldSceneInfo.newBuilder().setSceneId(scene).setIsLocked(false); var worldInfoBuilder = PlayerWorldSceneInfo.newBuilder().setSceneId(scene).setIsLocked(false);
/** Add scene-specific data */ /* Add scene-specific data */
// Scenetags // Scenetags
if (sceneTags.keySet().contains(scene)) { if (sceneTags.keySet().contains(scene)) {