refactor: replace concatenation log with parameterized

This commit is contained in:
Breno A. 2024-06-09 09:35:38 -03:00
parent 77e246213f
commit 6e7418a89d
34 changed files with 120 additions and 221 deletions

View File

@ -312,7 +312,7 @@ public final class Grasscutter {
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() {

View File

@ -53,7 +53,7 @@ public final class CommandMap {
* @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 final class CommandMap {
* @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;
@ -230,15 +230,9 @@ public final class CommandMap {
if (SERVER.logCommands) {
if (player != null) {
Grasscutter.getLogger()
.info(
"Command used by ["
+ player.getAccount().getUsername()
+ " (Player UID: "
+ player.getUid()
+ ")]: "
+ rawMessage);
.info("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,12 +344,10 @@ public final class CommandMap {
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(),
exception);
.error("Failed to register command handler for {}", annotated.getSimpleName(), exception);
}
});
}

View File

@ -88,7 +88,7 @@ public class DataLoader {
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);
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);
@ -119,9 +119,9 @@ 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");
Grasscutter.getLogger().debug("Creating default '{}' data", name);
FileUtils.copyResource("/defaults/data/" + name, filePath.toString());
}
}

View File

@ -655,7 +655,7 @@ public final class GameData {
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;

View File

@ -63,7 +63,7 @@ public final class ResourceLoader {
private static List<Set<Class<?>>> 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<ResourceType.LoadPriority, Set<Class<?>>>(priorities.size());
priorities.forEach(p -> map.put(p, new HashSet<>()));
@ -159,11 +159,11 @@ public final class ResourceLoader {
}));
errors.forEach(
pair ->
Grasscutter.getLogger()
.error("Error loading resource file: " + pair.left(), pair.right()));
Grasscutter.getLogger()
.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")
@ -281,7 +281,7 @@ public final class ResourceLoader {
}
});
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.");
}
@ -402,7 +402,7 @@ public final class ResourceLoader {
.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);
}
}
@ -464,7 +464,7 @@ public final class ResourceLoader {
path, String.class, new TypeToken<List<TalentData>>() {}.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);
}
}
@ -531,7 +531,7 @@ public final class ResourceLoader {
});
} 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;
}
}
@ -587,7 +587,7 @@ public final class ResourceLoader {
}
Grasscutter.getLogger()
.debug("Loaded " + GameData.getMainQuestDataMap().size() + " MainQuestDatas.");
.debug("Loaded {} MainQuestDatas.", GameData.getMainQuestDataMap().size());
}
public static void loadScriptSceneData() {
@ -605,7 +605,7 @@ public final class ResourceLoader {
}
});
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.");
}
@ -629,10 +629,7 @@ public final class ResourceLoader {
}
});
Grasscutter.getLogger()
.debug(
"Loaded "
+ GameData.getHomeworldDefaultSaveData().size()
+ " HomeworldDefaultSaveDatas.");
.debug("Loaded {} HomeworldDefaultSaveDatas.", GameData.getHomeworldDefaultSaveData().size());
} catch (IOException e) {
Grasscutter.getLogger().error("Failed to load HomeworldDefaultSave folder.");
}
@ -657,7 +654,7 @@ public final class ResourceLoader {
}
});
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.");
}

View File

@ -550,7 +550,7 @@ public final class DatabaseHelper {
.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;
}

View File

@ -177,15 +177,7 @@ public final class AbilityManager extends BasePlayerManager {
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
Grasscutter.getLogger()
.trace(
"Ability invoke: "
+ invoke
+ " "
+ invoke.getArgumentType()
+ " ("
+ invoke.getArgumentTypeValue()
+ "): "
+ this.player.getScene().getEntityById(invoke.getEntityId()));
.trace("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()
@ -212,7 +204,7 @@ public final class AbilityManager extends BasePlayerManager {
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);

View File

@ -96,12 +96,7 @@ public class GachaBanner {
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.");
.error("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;
}

View File

@ -322,10 +322,7 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
case MATERIAL_COSTUME:
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.");
.warn("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) {

View File

@ -35,12 +35,7 @@ public class MailHandler extends BasePlayerManager {
this.mail.add(message);
Grasscutter.getLogger()
.debug(
"Mail sent to user ["
+ this.getPlayer().getUid()
+ ":"
+ this.getPlayer().getNickname()
+ "]!");
.debug("Mail sent to user [{}:{}]!", this.getPlayer().getUid(), this.getPlayer().getNickname());
if (this.getPlayer().isOnline()) {
this.getPlayer().sendPacket(new PacketMailChangeNotify(this.getPlayer(), message));

View File

@ -104,7 +104,7 @@ public class SotSManager extends BasePlayerManager {
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 class SotSManager extends BasePlayerManager {
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 class SotSManager extends BasePlayerManager {
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);
}
}
@ -181,11 +180,7 @@ public class SotSManager extends BasePlayerManager {
public void run() {
refillSpringVolume();
logger.trace(
"isAutoRecoveryEnabled: "
+ getIsAutoRecoveryEnabled()
+ "\tautoRecoverPercentage: "
+ getAutoRecoveryPercentage());
logger.trace("isAutoRecoveryEnabled: {}\tautoRecoverPercentage: {}", getIsAutoRecoveryEnabled(), getAutoRecoveryPercentage());
if (getIsAutoRecoveryEnabled()) {
List<EntityAvatar> activeTeam = player.getTeamManager().getActiveTeam();

View File

@ -101,7 +101,7 @@ public class BlossomManager {
}
}
Grasscutter.getLogger().info("Blossom Monsters:" + monsters);
Grasscutter.getLogger().info("Blossom Monsters:{}", monsters);
activity = new BlossomActivity(entityGadget, monsters, -1, worldLevel);
blossomActivities.add(activity);
@ -203,7 +203,7 @@ public class BlossomManager {
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();

View File

@ -229,8 +229,7 @@ public class StaminaManager extends BasePlayerManager {
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 class StaminaManager extends BasePlayerManager {
for (Map.Entry<String, BeforeUpdateStaminaListener> 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 class StaminaManager extends BasePlayerManager {
for (Map.Entry<String, BeforeUpdateStaminaListener> 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 class StaminaManager extends BasePlayerManager {
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;
@ -499,7 +491,7 @@ public class StaminaManager extends BasePlayerManager {
// 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 @@ public class StaminaManager extends BasePlayerManager {
// 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);
}

View File

@ -93,7 +93,7 @@ public class ShopSystem extends BaseGameSystem {
}
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);
}

View File

@ -82,12 +82,7 @@ public class InventorySystem extends BaseGameSystem {
val avatarData = avatar.getSkillDepot();
if (avatarData == null) {
Grasscutter.getLogger()
.error(
"Attempted to check constellation level for UID"
+ player.getUid()
+ "'s avatar "
+ avatarId
+ " but avatar has no skillDepot!");
.error("Attempted to check constellation level for UID{}'s avatar {} but avatar has no skillDepot!", player.getUid(), avatarId);
return 0;
}
int constItemId = avatarData.getTalentCostItemId();

View File

@ -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 @@ public abstract class Plugin {
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);
}
}

View File

@ -887,7 +887,7 @@ public class SceneScriptManager {
}
} 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 +913,7 @@ public class SceneScriptManager {
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();

View File

@ -73,9 +73,7 @@ public class SceneBlock {
SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.pos.toPoint());
} catch (ScriptException exception) {
Grasscutter.getLogger()
.error(
"An error occurred while loading block " + this.id + " in scene " + sceneId,
exception);
.error("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;

View File

@ -168,8 +168,7 @@ public final class SceneGroup {
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(

View File

@ -29,7 +29,7 @@ public class SceneMeta {
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;
}

View File

@ -41,7 +41,7 @@ public final class GameServerPacketHandler {
// 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 +91,7 @@ public final class GameServerPacketHandler {
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));
}
}
}

View File

@ -99,7 +99,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
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));
}

View File

@ -66,8 +66,7 @@ public final class 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);
});
}

View File

@ -18,7 +18,7 @@ final class RootRequestHandler implements DocumentationHandler {
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;
}

View File

@ -22,7 +22,7 @@ public final class AnnouncementsHandler implements Router {
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 @@ public final class AnnouncementsHandler implements Router {
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 @@ public final class AnnouncementsHandler implements Router {
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);
}
}

View File

@ -38,13 +38,11 @@ public final class HttpJsonResponse implements Handler {
&& Arrays.stream(missingRoutes)
.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)" : ""));
.info("{}{}", translate(
"messages.dispatch.request",
Utils.address(ctx),
ctx.method(),
ctx.endpointHandlerPath()), DISPATCH_INFO.logRequests == ServerDebugMode.MISSING ? "(MISSING)" : "");
}
ctx.result(response);
}

View File

@ -17,7 +17,7 @@ public class WebStaticVersionResponse implements Handler {
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);
}

View File

@ -129,13 +129,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
int maxDelay = 200;
long actualDelay = System.currentTimeMillis() - cachedLandingTimeMillisecond;
Grasscutter.getLogger()
.trace(
"MOTION_FALL_ON_GROUND received after "
+ actualDelay
+ "/"
+ maxDelay
+ "ms."
+ (actualDelay > maxDelay ? " Discard" : ""));
.trace("MOTION_FALL_ON_GROUND received after {}/{}ms.{}", actualDelay, maxDelay, actualDelay > maxDelay ? " Discard" : "");
if (actualDelay > maxDelay) {
return;
}
@ -161,20 +155,9 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
}
if (damageFactor > 0) {
Grasscutter.getLogger()
.debug(
currentHP
+ "/"
+ maxHP
+ "\tLandingSpeed: "
+ cachedLandingSpeed
+ "\tDamageFactor: "
+ damageFactor
+ "\tDamage: "
+ damage
+ "\tNewHP: "
+ newHP);
.debug("{}/{}\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

View File

@ -155,12 +155,11 @@ public final class TaskMap {
}
} else {
Grasscutter.getLogger()
.error("Class " + annotated.getName() + " is not a TaskHandler!");
.error("Class {} is not a TaskHandler!", annotated.getName());
}
} catch (Exception exception) {
Grasscutter.getLogger()
.error(
"Failed to register task handler for " + annotated.getSimpleName(), exception);
.error("Failed to register task handler for {}", annotated.getSimpleName(), exception);
}
});
try {

View File

@ -314,10 +314,10 @@ public final class Tools {
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);
}
}
}
@ -342,7 +342,7 @@ public final class Tools {
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<String> getAvailableLanguage() {

View File

@ -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,10 +82,10 @@ 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 + "\"");
.error("Failed to find ExcelBinOutput in resources zip \"" + resources + "\"");
}
} catch (IOException e) {
Grasscutter.getLogger().error("Failed to scan resources zip \"" + resources + "\"");
@ -176,7 +176,7 @@ public final class FileUtils {
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 final class FileUtils {
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 final class FileUtils {
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 final class FileUtils {
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);
}
}

View File

@ -228,12 +228,10 @@ public final class TsvUtils {
return tree.toClass(classType, null);
} 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);
.warn("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 +245,7 @@ public final class TsvUtils {
})
.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;
}
}
@ -285,12 +283,10 @@ public final class TsvUtils {
return obj;
} 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);
.warn("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;
}
@ -298,17 +294,14 @@ public final class TsvUtils {
.toList();
} 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("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 +329,7 @@ public final class TsvUtils {
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();
@ -405,27 +398,21 @@ public final class TsvUtils {
return constructor.newInstance(args);
} catch (Exception e) {
Grasscutter.getLogger()
.warn(
"Error deserializing an instance of class "
+ classType.getCanonicalName()
+ " : "
+ constructor.getName());
Grasscutter.getLogger().warn("At token #" + t + " of #" + m);
.warn("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);
.warn("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 +420,7 @@ public final class TsvUtils {
.toList();
} catch (IOException e) {
Grasscutter.getLogger()
.error("Error loading file '" + filename + "' - Stacktrace is: ", e);
.error("Error loading file '{}' - Stacktrace is: ", filename, e);
return null;
}
})
@ -582,23 +569,14 @@ public final class TsvUtils {
// System.out.println("Exception while setting field "+name+" for class "+objClass+"
// - "+e);
Grasscutter.getLogger()
.error(
"Exception while setting field "
+ name
+ " ("
+ field.classType
+ ")"
+ " for class "
+ objClass
+ " - ",
e);
.error("Exception while setting field {} ({}) for class {} - ", name, field.classType, objClass, e);
}
});
return obj;
} 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;
}
}

View File

@ -69,7 +69,7 @@ public final class Utils {
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 final class Utils {
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 final class Utils {
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;
}
}

View File

@ -44,7 +44,7 @@ public final class Language {
.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 +99,7 @@ public final class Language {
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 +134,7 @@ public final class Language {
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 +194,7 @@ public final class Language {
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 +205,7 @@ public final class Language {
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 +241,7 @@ public final class Language {
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;
@ -361,7 +361,7 @@ public final class Language {
} catch (NoSuchFileException ignored) {
// Cache doesn't exist, generate it.
} catch (Exception exception) {
Grasscutter.getLogger().error("Error loading textmaps cache: " + exception);
Grasscutter.getLogger().error("Error loading textmaps cache: {}", exception);
}
// Regenerate cache