diff --git a/build.gradle b/build.gradle index 36acaba0f..d4500beca 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ spotless { target fileTree(rootDir) { include '**/*.java' exclude '**/generated/**/*.*' + exclude '.idea/**/*.*' } importOrder('io.grasscutter', '', 'java', 'javax', '\\#java', '\\#') // Configure import order. @@ -57,7 +58,7 @@ sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 group = 'io.grasscutter' -version = '1.6.3' +version = '1.7.0' java { withJavadocJar() diff --git a/src/main/java/emu/grasscutter/command/commands/QuestCommand.java b/src/main/java/emu/grasscutter/command/commands/QuestCommand.java index cb4c981b0..3b4aeb540 100644 --- a/src/main/java/emu/grasscutter/command/commands/QuestCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/QuestCommand.java @@ -1,15 +1,14 @@ package emu.grasscutter.command.commands; +import static emu.grasscutter.utils.lang.Language.translate; + import emu.grasscutter.command.*; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.GameQuest; import emu.grasscutter.game.quest.enums.*; - import java.util.*; import java.util.stream.Collectors; -import static emu.grasscutter.utils.lang.Language.translate; - @Command( label = "quest", aliases = {"q"}, @@ -155,19 +154,21 @@ public final class QuestCommand implements CommandHandler { case "list" -> { var questManager = targetPlayer.getQuestManager(); var mainQuests = questManager.getActiveMainQuests(); - var allQuestIds = mainQuests.stream() - .filter(quest -> questManager.getLoggedQuests().contains(quest.getParentQuestId())) - .filter(quest -> quest.getState() != ParentQuestState.PARENT_QUEST_STATE_FINISHED) - .map(quest -> quest.getChildQuests().values()) - .flatMap(Collection::stream) - .filter(quest -> quest.getState() == QuestState.QUEST_STATE_UNFINISHED) - .map(GameQuest::getSubQuestId) - .map(String::valueOf) - .toList(); + var allQuestIds = + mainQuests.stream() + .filter(quest -> questManager.getLoggedQuests().contains(quest.getParentQuestId())) + .filter(quest -> quest.getState() != ParentQuestState.PARENT_QUEST_STATE_FINISHED) + .map(quest -> quest.getChildQuests().values()) + .flatMap(Collection::stream) + .filter(quest -> quest.getState() == QuestState.QUEST_STATE_UNFINISHED) + .map(GameQuest::getSubQuestId) + .map(String::valueOf) + .toList(); - CommandHandler.sendMessage(sender, "Quests: " + - (allQuestIds.isEmpty() ? "(no active quests)" : - String.join(", ", allQuestIds))); + CommandHandler.sendMessage( + sender, + "Quests: " + + (allQuestIds.isEmpty() ? "(no active quests)" : String.join(", ", allQuestIds))); } default -> this.sendUsageMessage(sender); } diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java index f5b6db408..49e71c4de 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java @@ -3,9 +3,8 @@ package emu.grasscutter.data.binout; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.common.DynamicFloat; import emu.grasscutter.game.props.ElementType; -import lombok.ToString; - import java.io.Serializable; +import lombok.ToString; public class AbilityModifier implements Serializable { private static final long serialVersionUID = -2001232313615923575L; @@ -342,8 +341,10 @@ public class AbilityModifier implements Serializable { public int param3; public LuaCallType luaCallType; + @SerializedName("CallParamList") public int[] callParamList; + public String funcName; public String content; diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionDebugLog.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionDebugLog.java index a885b4eff..e5b021593 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionDebugLog.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionDebugLog.java @@ -10,9 +10,7 @@ import emu.grasscutter.game.entity.GameEntity; public final class ActionDebugLog extends AbilityActionHandler { @Override public boolean execute( - Ability ability, AbilityModifierAction action, - ByteString abilityData, GameEntity target - ) { + Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { Grasscutter.getLogger().debug("[Ability] DebugLog: {}", action.content); return true; } diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionServerLuaCall.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionServerLuaCall.java index a6aee3097..3a029bf79 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionServerLuaCall.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionServerLuaCall.java @@ -5,17 +5,14 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; import emu.grasscutter.game.ability.Ability; import emu.grasscutter.game.entity.GameEntity; -import org.luaj.vm2.LuaFunction; - import javax.script.Bindings; +import org.luaj.vm2.LuaFunction; @AbilityAction(AbilityModifierAction.Type.ServerLuaCall) public final class ActionServerLuaCall extends AbilityActionHandler { @Override public boolean execute( - Ability ability, AbilityModifierAction action, - ByteString abilityData, GameEntity target - ) { + Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity target) { var scene = target.getScene(); var scriptManager = scene.getScriptManager(); var functionName = action.funcName; @@ -58,8 +55,7 @@ public final class ActionServerLuaCall extends AbilityActionHandler { return true; } catch (Exception exception) { - Grasscutter.getLogger().warn("Unable to invoke {}.", - functionName, exception); + Grasscutter.getLogger().warn("Unable to invoke {}.", functionName, exception); return false; } } diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 2fbde7719..e144199c3 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -910,8 +910,7 @@ public final class Scene { public int loadDynamicGroup(int group_id) { SceneGroup group = getScriptManager().getGroupById(group_id); - if (group == null) - return -1; // Group not found + if (group == null) return -1; // Group not found this.onLoadGroup(new ArrayList<>(List.of(group))); diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 1eee758b7..4c461e1e0 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -1,5 +1,7 @@ package emu.grasscutter.scripts; +import static emu.grasscutter.scripts.constants.EventType.EVENT_TIMER_EVENT; + import com.github.davidmoten.rtreemulti.RTree; import com.github.davidmoten.rtreemulti.geometry.Geometry; import emu.grasscutter.Grasscutter; @@ -19,20 +21,17 @@ import emu.grasscutter.server.packet.send.PacketGroupSuiteNotify; import emu.grasscutter.utils.*; import io.netty.util.concurrent.FastThreadLocalThread; import it.unimi.dsi.fastutil.ints.*; -import kotlin.Pair; -import lombok.val; -import org.luaj.vm2.*; -import org.luaj.vm2.lib.jse.CoerceJavaToLua; - -import javax.annotation.*; import java.io.*; import java.nio.file.Files; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; - -import static emu.grasscutter.scripts.constants.EventType.EVENT_TIMER_EVENT; +import javax.annotation.*; +import kotlin.Pair; +import lombok.val; +import org.luaj.vm2.*; +import org.luaj.vm2.lib.jse.CoerceJavaToLua; public class SceneScriptManager { private final Scene scene; @@ -40,8 +39,7 @@ public class SceneScriptManager { private SceneMeta meta; private boolean isInit; - private final Map timeAxis - = new ConcurrentHashMap<>(); + private final Map timeAxis = new ConcurrentHashMap<>(); /** current triggers controlled by RefreshGroup */ private final Map> currentTriggers; @@ -399,7 +397,7 @@ public class SceneScriptManager { var instance = cachedSceneGroupsInstances.getOrDefault(groupId, null); if (instance == null) { instance = DatabaseHelper.loadGroupInstance(groupId, scene.getWorld().getHost()); - if (instance != null){ + if (instance != null) { cachedSceneGroupsInstances.put(groupId, instance); this.cachedSceneGroupsInstances.get(groupId).setCached(false); this.cachedSceneGroupsInstances.get(groupId).setLuaGroup(getGroupById(groupId)); @@ -833,9 +831,9 @@ public class SceneScriptManager { .filter( t -> (t.getName().length() <= 12 - || t.getName().substring(13).equals(String.valueOf(params.param1))) - && (t.getSource().isEmpty() - || t.getSource().equals(params.getEventSource()))) + || t.getName().substring(13).equals(String.valueOf(params.param1))) + && (t.getSource().isEmpty() + || t.getSource().equals(params.getEventSource()))) .collect(Collectors.toSet()); default -> this.getTriggersByEvent(eventType).stream() .filter( @@ -1203,8 +1201,7 @@ public class SceneScriptManager { } /** - * Registers a new time axis for this scene. - * Starts the time axis after. + * Registers a new time axis for this scene. Starts the time axis after. * * @param timeAxis The time axis. */ diff --git a/src/main/java/emu/grasscutter/scripts/SceneTimeAxis.java b/src/main/java/emu/grasscutter/scripts/SceneTimeAxis.java index 971068e4a..d43691b48 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneTimeAxis.java +++ b/src/main/java/emu/grasscutter/scripts/SceneTimeAxis.java @@ -2,9 +2,8 @@ package emu.grasscutter.scripts; import emu.grasscutter.scripts.constants.EventType; import emu.grasscutter.scripts.data.ScriptArgs; -import lombok.*; - import java.util.*; +import lombok.*; @Getter @RequiredArgsConstructor @@ -18,21 +17,16 @@ public final class SceneTimeAxis { private final int delay; private final boolean loop; - /** - * Schedules the task to run. - */ + /** Schedules the task to run. */ public void start() { if (this.loop) { - this.timer.scheduleAtFixedRate( - new Task(), this.delay, this.delay); + this.timer.scheduleAtFixedRate(new Task(), this.delay, this.delay); } else { this.timer.schedule(new Task(), this.delay); } } - /** - * Terminates a repeating task. - */ + /** Terminates a repeating task. */ public void stop() { this.timer.cancel(); } @@ -41,10 +35,9 @@ public final class SceneTimeAxis { @Override public void run() { // Invoke script event. - SceneTimeAxis.this.handle.callEvent(new ScriptArgs( - SceneTimeAxis.this.groupId, - EventType.EVENT_TIME_AXIS_PASS - ).setEventSource(SceneTimeAxis.this.identifier)); + SceneTimeAxis.this.handle.callEvent( + new ScriptArgs(SceneTimeAxis.this.groupId, EventType.EVENT_TIME_AXIS_PASS) + .setEventSource(SceneTimeAxis.this.identifier)); } } } diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java index 449b513d5..0eef5a5b2 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java @@ -8,18 +8,17 @@ import emu.grasscutter.scripts.constants.*; import emu.grasscutter.scripts.data.SceneMeta; import emu.grasscutter.scripts.serializer.*; import emu.grasscutter.utils.FileUtils; +import java.lang.ref.SoftReference; +import java.nio.file.*; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import javax.script.*; import lombok.Getter; import org.luaj.vm2.*; import org.luaj.vm2.lib.OneArgFunction; import org.luaj.vm2.lib.jse.CoerceJavaToLua; import org.luaj.vm2.script.LuajContext; -import javax.script.*; -import java.lang.ref.SoftReference; -import java.nio.file.*; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - public class ScriptLoader { private static ScriptEngineManager sm; @Getter private static ScriptEngine engine; @@ -110,8 +109,7 @@ public class ScriptLoader { public LuaValue call(LuaValue arg) { // Resolve the script path. var scriptName = arg.checkjstring(); - var scriptPath = FileUtils.getScriptPath( - "Common/" + scriptName + ".lua"); + var scriptPath = FileUtils.getScriptPath("Common/" + scriptName + ".lua"); // Load & compile the script. var script = ScriptLoader.getScript(scriptPath.toString()); @@ -124,8 +122,7 @@ public class ScriptLoader { script.eval(); } catch (Exception exception) { Grasscutter.getLogger() - .error("Loading script {} failed! - {}", - scriptPath, exception.getLocalizedMessage()); + .error("Loading script {} failed! - {}", scriptPath, exception.getLocalizedMessage()); } // TODO: What is the proper return value?