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;
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 <T1, T2> Map<T1, T2> loadMap(
String resourcePath, Class<T1> keyType, Class<T2> valueType) throws IOException {
public static <T1, T2> Map<T1, T2> loadMap(String resourcePath, Class<T1> keyType, Class<T2> valueType) throws IOException {
try (InputStreamReader reader = loadReader(resourcePath)) {
return JsonUtils.loadToMap(reader, keyType, valueType);
}
}
public static <T> List<T> loadTableToList(String resourcePath, Class<T> classType)
throws IOException {
public static <T> List<T> loadTableToList(String resourcePath, Class<T> 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());

View File

@ -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) {

View File

@ -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
*/

View File

@ -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;
}

View File

@ -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);

View File

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

View File

@ -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));
}

View File

@ -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) {

View File

@ -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));
}

View File

@ -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)) {