From 67c0e82dfb0ecc94b845126b8b4014e618651c53 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Wed, 30 Aug 2023 23:28:54 -0400 Subject: [PATCH] Logging changes (move levels down & add `toString` for some objects) --- src/main/java/emu/grasscutter/game/Account.java | 17 +++++++++++------ .../ActionSetGlobalValueToOverrideMap.java | 2 +- .../emu/grasscutter/game/player/Player.java | 6 ++++++ .../grasscutter/scripts/data/ScriptArgs.java | 3 +++ .../data/controller/EntityController.java | 10 ++++++++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index f74e825ea..1f5845fe4 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -1,15 +1,14 @@ package emu.grasscutter.game; -import static emu.grasscutter.config.Configuration.ACCOUNT; -import static emu.grasscutter.config.Configuration.LANGUAGE; - import dev.morphia.annotations.*; import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.utils.Crypto; -import emu.grasscutter.utils.Utils; +import emu.grasscutter.utils.*; +import org.bson.Document; + import java.util.*; import java.util.stream.Stream; -import org.bson.Document; + +import static emu.grasscutter.config.Configuration.*; @Entity(value = "accounts", useDiscriminator = false) public class Account { @@ -242,4 +241,10 @@ public class Account { this.locale = LANGUAGE; } } + + @Override + public String toString() { + return "Account ID: %s; Username: %s" + .formatted(this.id, this.username); + } } diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionSetGlobalValueToOverrideMap.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionSetGlobalValueToOverrideMap.java index 6432948e2..3642fa6b6 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionSetGlobalValueToOverrideMap.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionSetGlobalValueToOverrideMap.java @@ -24,7 +24,7 @@ public final class ActionSetGlobalValueToOverrideMap extends AbilityActionHandle var abilityFormula = action.abilityFormula; if (!entity.getGlobalAbilityValues().containsKey(globalValueKey)) { - Grasscutter.getLogger().debug("Action does not contains {} global key", globalValueKey); + Grasscutter.getLogger().trace("Action does not contains {} global key", globalValueKey); return true; } diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 39442cb01..8b587be4a 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -1545,6 +1545,12 @@ public class Player implements PlayerHook, FieldFetch { this.id == otherPlayer.getUid(); } + @Override + public String toString() { + return "Player UID: %s; Nickname: %s; Account: %s" + .formatted(this.id, this.nickname, this.account); + } + public enum SceneLoadState { NONE(0), LOADING(1), INIT(2), LOADED(3); diff --git a/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java b/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java index 788512b50..9e607861c 100644 --- a/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java +++ b/src/main/java/emu/grasscutter/scripts/data/ScriptArgs.java @@ -1,5 +1,8 @@ package emu.grasscutter.scripts.data; +import lombok.ToString; + +@ToString public class ScriptArgs { public int param1; public int param2; 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 42ec26680..217bb0425 100644 --- a/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java +++ b/src/main/java/emu/grasscutter/scripts/data/controller/EntityController.java @@ -4,10 +4,16 @@ import emu.grasscutter.*; import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.props.ElementType; import emu.grasscutter.scripts.*; -import javax.script.*; import org.luaj.vm2.*; +import javax.script.*; +import java.util.Set; + public class EntityController { + private static final Set SERVER_CALLED = Set.of( + "OnBeHurt", "OnDie", "OnTimer" + ); + private transient CompiledScript entityController; private transient Bindings entityControllerBindings; @@ -92,7 +98,7 @@ public class EntityController { error); ret = LuaValue.valueOf(-1); } - } else if (funcName != null && !funcName.equals("OnTimer")) { + } else if (funcName != null && !SERVER_CALLED.contains(funcName)) { ScriptLib.logger.error( "[LUA] unknown func in gadget {} with {} {} {} {}", entity.getEntityTypeId(),