From ee298235c24a1fde3f93edc5f8c211933a35d977 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Tue, 18 Apr 2023 17:17:55 -0400 Subject: [PATCH] Run `spotlessApply` --- .../java/emu/grasscutter/data/GameData.java | 19 +- .../emu/grasscutter/data/ResourceLoader.java | 177 +++++++++------ .../grasscutter/data/common/DropItemData.java | 3 +- .../data/excels/DropMaterialData.java | 1 + .../data/excels/DropTableData.java | 8 +- .../data/excels/dungeon/DungeonData.java | 3 +- .../emu/grasscutter/data/server/Grid.java | 11 +- .../emu/grasscutter/game/avatar/Avatar.java | 35 ++- .../emu/grasscutter/game/drop/DropSystem.java | 35 +-- .../game/drop/DropSystemLegacy.java | 27 ++- .../game/entity/gadget/GadgetChest.java | 108 +++++++--- .../game/managers/ResinManager.java | 31 ++- .../props/ItemUseAction/ItemUseAddItem.java | 8 +- .../grasscutter/game/quest/GameMainQuest.java | 12 +- .../emu/grasscutter/game/quest/GameQuest.java | 37 ++-- .../game/quest/exec/ExecNotifyGroupLua.java | 4 +- .../emu/grasscutter/game/world/Scene.java | 31 +-- .../emu/grasscutter/game/world/World.java | 8 +- .../EntityControllerScriptManager.java | 32 ++- .../grasscutter/scripts/data/SceneGadget.java | 8 +- .../grasscutter/server/game/GameServer.java | 13 +- .../server/http/dispatch/RegionHandler.java | 204 ++++++++++-------- .../packet/recv/HandlerChangeGameTimeReq.java | 4 +- .../recv/HandlerCombatInvocationsNotify.java | 6 +- .../recv/HandlerDungeonEntryInfoReq.java | 5 +- .../recv/HandlerPlayerEnterDungeonReq.java | 13 +- .../packet/recv/HandlerPostEnterSceneReq.java | 6 +- .../packet/recv/HandlerQuestTransmitReq.java | 17 +- .../packet/recv/HandlerSceneAudioNotify.java | 10 +- .../recv/HandlerSetPlayerBornDataReq.java | 2 +- .../recv/HandlerUnlockPersonalLineReq.java | 4 +- .../PacketAvatarFightPropUpdateNotify.java | 1 - .../send/PacketAvatarTeamUpdateNotify.java | 11 +- .../server/packet/send/PacketBuyResinRsp.java | 9 +- .../packet/send/PacketChangeGameTimeRsp.java | 6 +- .../packet/send/PacketDropHintNotify.java | 4 +- .../send/PacketDungeonEntryInfoRsp.java | 12 +- .../packet/send/PacketResinChangeNotify.java | 13 +- .../packet/send/PacketSceneAudioNotify.java | 22 +- .../PacketServerGlobalValueChangeNotify.java | 8 +- .../send/PacketWorldChestOpenNotify.java | 13 +- .../task/tasks/AnnouncementTask.java | 3 +- .../java/emu/grasscutter/utils/Crypto.java | 29 +-- .../java/emu/grasscutter/utils/Language.java | 9 +- 44 files changed, 598 insertions(+), 424 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 2a4a359df..118760d6d 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -189,26 +189,33 @@ public final class GameData { @Getter private static final Int2ObjectMap cookRecipeDataMap = - new Int2ObjectOpenHashMap<>(); + new Int2ObjectOpenHashMap<>(); @Getter private static final Int2ObjectMap compoundDataMap = new Int2ObjectOpenHashMap<>(); @Getter private static final Int2ObjectMap dailyDungeonDataMap = - new Int2ObjectOpenHashMap<>(); - @Getter private static final Int2ObjectMap dropTableDataMap = new Int2ObjectOpenHashMap<>(); - @Getter private static final Int2ObjectMap dropMaterialDataMap = new Int2ObjectOpenHashMap<>(); + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap dropTableDataMap = + new Int2ObjectOpenHashMap<>(); + + @Getter + private static final Int2ObjectMap dropMaterialDataMap = + new Int2ObjectOpenHashMap<>(); + @Getter private static final Int2ObjectMap dungeonDataMap = new Int2ObjectOpenHashMap<>(); @Getter private static final Int2ObjectMap dungeonEntryDataMap = - new Int2ObjectOpenHashMap<>(); + new Int2ObjectOpenHashMap<>(); @Getter private static final Int2ObjectMap envAnimalGatherConfigDataMap = - new Int2ObjectOpenHashMap<>(); + new Int2ObjectOpenHashMap<>(); @Getter private static final Int2ObjectMap equipAffixDataMap = diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index 1332942aa..65fa4b714 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -44,11 +44,10 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import lombok.val; -import org.reflections.Reflections; - import javax.script.Bindings; import javax.script.CompiledScript; +import lombok.val; +import org.reflections.Reflections; public final class ResourceLoader { @@ -666,27 +665,31 @@ public final class ResourceLoader { val pattern = Pattern.compile("ConfigLevelEntity_(.+?)\\.json"); try { - var stream = Files.newDirectoryStream(getResourcePath("BinOutput/LevelEntity/"), "ConfigLevelEntity_*.json"); - stream.forEach(path -> { - val matcher = pattern.matcher(path.getFileName().toString()); - if (!matcher.find()) return; - Map config; + var stream = + Files.newDirectoryStream( + getResourcePath("BinOutput/LevelEntity/"), "ConfigLevelEntity_*.json"); + stream.forEach( + path -> { + val matcher = pattern.matcher(path.getFileName().toString()); + if (!matcher.find()) return; + Map config; - try { - config = JsonUtils.loadToMap(path, String.class, ConfigLevelEntity.class); - } catch (Exception e) { - Grasscutter.getLogger().error("Error loading player ability embryos:", e); - return; - } - GameData.getConfigLevelEntityDataMap().putAll(config); - }); + try { + config = JsonUtils.loadToMap(path, String.class, ConfigLevelEntity.class); + } catch (Exception e) { + Grasscutter.getLogger().error("Error loading player ability embryos:", e); + return; + } + GameData.getConfigLevelEntityDataMap().putAll(config); + }); stream.close(); } catch (IOException e) { Grasscutter.getLogger().error("Error loading config level entity: no files found"); return; } - if (GameData.getConfigLevelEntityDataMap() == null || GameData.getConfigLevelEntityDataMap().isEmpty()) { + if (GameData.getConfigLevelEntityDataMap() == null + || GameData.getConfigLevelEntityDataMap().isEmpty()) { Grasscutter.getLogger().error("No config level entity loaded!"); return; } @@ -698,33 +701,52 @@ public final class ResourceLoader { try { var bindings = ScriptLoader.getEngine().createBindings(); - var stream = Files.newDirectoryStream(getResourcePath("Scripts/Quest/Share/"), "Q*ShareConfig.lua"); - stream.forEach(path -> { - val matcher = pattern.matcher(path.getFileName().toString()); - if (!matcher.find()) return; + var stream = + Files.newDirectoryStream(getResourcePath("Scripts/Quest/Share/"), "Q*ShareConfig.lua"); + stream.forEach( + path -> { + val matcher = pattern.matcher(path.getFileName().toString()); + if (!matcher.find()) return; - var cs = ScriptLoader.getScript("Quest/Share/" + path.getFileName().toString()); - if (cs == null) return; + var cs = ScriptLoader.getScript("Quest/Share/" + path.getFileName().toString()); + if (cs == null) return; - try{ - cs.eval(bindings); - // these are Map - var teleportDataMap = ScriptLoader.getSerializer().toMap(TeleportData.class, bindings.get("quest_data")); - var rewindDataMap = ScriptLoader.getSerializer().toMap(RewindData.class, bindings.get("rewind_data")); - // convert them to Map and cache - GameData.getTeleportDataMap().putAll(teleportDataMap.entrySet().stream().collect(Collectors.toMap(entry -> Integer.valueOf(entry.getKey()), Entry::getValue))); - GameData.getRewindDataMap().putAll(rewindDataMap.entrySet().stream().collect(Collectors.toMap(entry -> Integer.valueOf(entry.getKey()), Entry::getValue))); - } catch (Throwable e){ - Grasscutter.getLogger().error("Error while loading Quest Share Config: {}", path.getFileName().toString()); - } - }); + try { + cs.eval(bindings); + // these are Map + var teleportDataMap = + ScriptLoader.getSerializer() + .toMap(TeleportData.class, bindings.get("quest_data")); + var rewindDataMap = + ScriptLoader.getSerializer().toMap(RewindData.class, bindings.get("rewind_data")); + // convert them to Map and cache + GameData.getTeleportDataMap() + .putAll( + teleportDataMap.entrySet().stream() + .collect( + Collectors.toMap( + entry -> Integer.valueOf(entry.getKey()), Entry::getValue))); + GameData.getRewindDataMap() + .putAll( + rewindDataMap.entrySet().stream() + .collect( + Collectors.toMap( + entry -> Integer.valueOf(entry.getKey()), Entry::getValue))); + } catch (Throwable e) { + Grasscutter.getLogger() + .error( + "Error while loading Quest Share Config: {}", path.getFileName().toString()); + } + }); stream.close(); } catch (IOException e) { Grasscutter.getLogger().error("Error loading Quest Share Config: no files found"); return; } - if (GameData.getTeleportDataMap() == null || GameData.getTeleportDataMap().isEmpty() - || GameData.getRewindDataMap() == null || GameData.getRewindDataMap().isEmpty()) { + if (GameData.getTeleportDataMap() == null + || GameData.getTeleportDataMap().isEmpty() + || GameData.getRewindDataMap() == null + || GameData.getRewindDataMap().isEmpty()) { Grasscutter.getLogger().error("No Quest Share Config loaded!"); return; } @@ -735,8 +757,9 @@ public final class ResourceLoader { val gadgetMap = GameData.getGadgetMappingMap(); try { JsonUtils.loadToList(getResourcePath("Server/GadgetMapping.json"), GadgetMapping.class) - .forEach(entry -> gadgetMap.put(entry.getGadgetId(), entry)); - } catch (IOException | NullPointerException ignored) {} + .forEach(entry -> gadgetMap.put(entry.getGadgetId(), entry)); + } catch (IOException | NullPointerException ignored) { + } Grasscutter.getLogger().debug("Loaded {} gadget mappings.", gadgetMap.size()); } catch (Exception e) { Grasscutter.getLogger().error("Unable to load gadget mappings.", e); @@ -747,8 +770,11 @@ public final class ResourceLoader { try { val gadgetMap = GameData.getActivityCondGroupMap(); try { - JsonUtils.loadToList(getResourcePath("Server/ActivityCondGroups.json"), ActivityCondGroup.class).forEach(entry -> gadgetMap.put(entry.getCondGroupId(), entry)); - } catch (IOException | NullPointerException ignored) {} + JsonUtils.loadToList( + getResourcePath("Server/ActivityCondGroups.json"), ActivityCondGroup.class) + .forEach(entry -> gadgetMap.put(entry.getCondGroupId(), entry)); + } catch (IOException | NullPointerException ignored) { + } Grasscutter.getLogger().debug("Loaded {} ActivityCondGroups.", gadgetMap.size()); } catch (Exception e) { Grasscutter.getLogger().error("Unable to load ActivityCondGroups.", e); @@ -760,40 +786,47 @@ public final class ResourceLoader { String pathName = "CustomResources/TrialAvatarExcels/"; try { JsonUtils.loadToList( - getResourcePath(pathName + "TrialAvatarActivityDataExcelConfigData.json"), - TrialAvatarActivityDataData.class).forEach(instance -> { - instance.onLoad(); - GameData.getTrialAvatarActivityDataCustomData() - .put(instance.getTrialAvatarIndexId(), instance); - }); - } catch (IOException | NullPointerException ignored) {} + getResourcePath(pathName + "TrialAvatarActivityDataExcelConfigData.json"), + TrialAvatarActivityDataData.class) + .forEach( + instance -> { + instance.onLoad(); + GameData.getTrialAvatarActivityDataCustomData() + .put(instance.getTrialAvatarIndexId(), instance); + }); + } catch (IOException | NullPointerException ignored) { + } Grasscutter.getLogger().debug("Loaded trial activity custom data."); try { JsonUtils.loadToList( - getResourcePath(pathName + "TrialAvatarActivityExcelConfigData.json"), - TrialAvatarActivityCustomData.class).forEach(instance -> { - instance.onLoad(); - GameData.getTrialAvatarActivityCustomData() - .put(instance.getScheduleId(), instance); - }); - } catch (IOException | NullPointerException ignored) {} + getResourcePath(pathName + "TrialAvatarActivityExcelConfigData.json"), + TrialAvatarActivityCustomData.class) + .forEach( + instance -> { + instance.onLoad(); + GameData.getTrialAvatarActivityCustomData() + .put(instance.getScheduleId(), instance); + }); + } catch (IOException | NullPointerException ignored) { + } Grasscutter.getLogger().debug("Loaded trial activity schedule custom data."); try { JsonUtils.loadToList( - getResourcePath(pathName + "TrialAvatarData.json"), - TrialAvatarCustomData.class).forEach(instance -> { - instance.onLoad(); - GameData.getTrialAvatarCustomData() - .put(instance.getTrialAvatarId(), instance); - }); - } catch (IOException | NullPointerException ignored) {} + getResourcePath(pathName + "TrialAvatarData.json"), TrialAvatarCustomData.class) + .forEach( + instance -> { + instance.onLoad(); + GameData.getTrialAvatarCustomData().put(instance.getTrialAvatarId(), instance); + }); + } catch (IOException | NullPointerException ignored) { + } Grasscutter.getLogger().debug("Loaded trial avatar custom data."); } catch (Exception e) { Grasscutter.getLogger().error("Unable to load trial avatar custom data.", e); } } - private static void loadGroupReplacements(){ + private static void loadGroupReplacements() { Bindings bindings = ScriptLoader.getEngine().createBindings(); CompiledScript cs = ScriptLoader.getScript("Scene/groups_replacement.lua"); @@ -802,21 +835,29 @@ public final class ResourceLoader { return; } - try{ + try { cs.eval(bindings); // these are Map - var replacementsMap = ScriptLoader.getSerializer().toMap(GroupReplacementData.class, bindings.get("replacements")); + var replacementsMap = + ScriptLoader.getSerializer() + .toMap(GroupReplacementData.class, bindings.get("replacements")); // convert them to Map and cache - GameData.getGroupReplacements().putAll(replacementsMap.entrySet().stream().collect(Collectors.toMap(entry -> Integer.valueOf(entry.getValue().getId()), Entry::getValue))); + GameData.getGroupReplacements() + .putAll( + replacementsMap.entrySet().stream() + .collect( + Collectors.toMap( + entry -> Integer.valueOf(entry.getValue().getId()), Entry::getValue))); - } catch (Throwable e){ + } catch (Throwable e) { Grasscutter.getLogger().error("Error while loading Group Replacements"); } if (GameData.getGroupReplacements() == null || GameData.getGroupReplacements().isEmpty()) { Grasscutter.getLogger().error("No Group Replacements loaded!"); } else { - Grasscutter.getLogger().debug("Loaded {} group replacements.", GameData.getGroupReplacements().size()); + Grasscutter.getLogger() + .debug("Loaded {} group replacements.", GameData.getGroupReplacements().size()); } } diff --git a/src/main/java/emu/grasscutter/data/common/DropItemData.java b/src/main/java/emu/grasscutter/data/common/DropItemData.java index 6c3842350..401162f91 100644 --- a/src/main/java/emu/grasscutter/data/common/DropItemData.java +++ b/src/main/java/emu/grasscutter/data/common/DropItemData.java @@ -5,8 +5,9 @@ import lombok.Getter; @Getter public class DropItemData { - @SerializedName(value="itemId") + @SerializedName(value = "itemId") private int id; + private String countRange; private int weight; } diff --git a/src/main/java/emu/grasscutter/data/excels/DropMaterialData.java b/src/main/java/emu/grasscutter/data/excels/DropMaterialData.java index f3cfacc8d..62af9e2f6 100644 --- a/src/main/java/emu/grasscutter/data/excels/DropMaterialData.java +++ b/src/main/java/emu/grasscutter/data/excels/DropMaterialData.java @@ -9,6 +9,7 @@ import lombok.Getter; public class DropMaterialData extends GameResource { @Getter(onMethod_ = @Override) private int id; + private boolean useOnGain; private boolean disableFirstGainHint; private boolean autoPick; diff --git a/src/main/java/emu/grasscutter/data/excels/DropTableData.java b/src/main/java/emu/grasscutter/data/excels/DropTableData.java index 31e4d7468..b1d3eac09 100644 --- a/src/main/java/emu/grasscutter/data/excels/DropTableData.java +++ b/src/main/java/emu/grasscutter/data/excels/DropTableData.java @@ -4,15 +4,17 @@ import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType.LoadPriority; import emu.grasscutter.data.common.DropItemData; +import java.util.List; import lombok.Getter; -import java.util.List; - -@ResourceType(name ={"DropTableExcelConfigData.json","DropSubTableExcelConfigData.json"} , loadPriority = LoadPriority.HIGH) +@ResourceType( + name = {"DropTableExcelConfigData.json", "DropSubTableExcelConfigData.json"}, + loadPriority = LoadPriority.HIGH) @Getter public class DropTableData extends GameResource { @Getter(onMethod_ = @Override) private int id; + private int randomType; private int dropLevel; private List dropVec; diff --git a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java index b63519921..21d5f1c51 100644 --- a/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java +++ b/src/main/java/emu/grasscutter/data/excels/dungeon/DungeonData.java @@ -5,10 +5,9 @@ import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.excels.RewardPreviewData; import emu.grasscutter.game.dungeons.enums.*; -import java.util.List; - import emu.grasscutter.scripts.data.SceneMeta; import emu.grasscutter.utils.Position; +import java.util.List; import lombok.Getter; @ResourceType(name = "DungeonExcelConfigData.json") diff --git a/src/main/java/emu/grasscutter/data/server/Grid.java b/src/main/java/emu/grasscutter/data/server/Grid.java index fe42129f4..3c4ed57a0 100644 --- a/src/main/java/emu/grasscutter/data/server/Grid.java +++ b/src/main/java/emu/grasscutter/data/server/Grid.java @@ -3,7 +3,6 @@ package emu.grasscutter.data.server; import emu.grasscutter.Grasscutter; import emu.grasscutter.utils.GridPosition; import emu.grasscutter.utils.Position; - import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; @@ -11,15 +10,11 @@ import java.util.Set; public class Grid { public Map> grid; - public Map> gridMap - = new LinkedHashMap<>(); + public Map> gridMap = new LinkedHashMap<>(); - /** - * Loads the correct grid map. - */ + /** Loads the correct grid map. */ public void load() { - this.grid.forEach((position, groups) -> - this.gridMap.put(new GridPosition(position), groups)); + this.grid.forEach((position, groups) -> this.gridMap.put(new GridPosition(position), groups)); } /** diff --git a/src/main/java/emu/grasscutter/game/avatar/Avatar.java b/src/main/java/emu/grasscutter/game/avatar/Avatar.java index d6a778c0f..aba83ffb0 100644 --- a/src/main/java/emu/grasscutter/game/avatar/Avatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/Avatar.java @@ -45,7 +45,6 @@ import java.util.*; import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; - import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -138,17 +137,17 @@ public class Avatar { // Combat properties Stream.of(FightProperty.values()) - .map(FightProperty::getId) - .filter(id -> (id > 0) && (id < 3000)) - .forEach(id -> this.setFightProperty(id, 0f)); + .map(FightProperty::getId) + .filter(id -> (id > 0) && (id < 3000)) + .forEach(id -> this.setFightProperty(id, 0f)); - this.setSkillDepotData(switch (this.getAvatarId()) { - case GameConstants.MAIN_CHARACTER_MALE -> - GameData.getAvatarSkillDepotDataMap().get(501); - case GameConstants.MAIN_CHARACTER_FEMALE -> - GameData.getAvatarSkillDepotDataMap().get(701); - default -> data.getSkillDepot(); - }); + this.setSkillDepotData( + switch (this.getAvatarId()) { + case GameConstants.MAIN_CHARACTER_MALE -> GameData.getAvatarSkillDepotDataMap().get(501); + case GameConstants.MAIN_CHARACTER_FEMALE -> GameData.getAvatarSkillDepotDataMap() + .get(701); + default -> data.getSkillDepot(); + }); // Set stats this.recalcStats(); @@ -180,10 +179,8 @@ public class Avatar { * @return True if the avatar is a main character. */ public boolean isMainCharacter() { - return List.of( - GameConstants.MAIN_CHARACTER_MALE, - GameConstants.MAIN_CHARACTER_FEMALE - ).contains(this.getAvatarId()); + return List.of(GameConstants.MAIN_CHARACTER_MALE, GameConstants.MAIN_CHARACTER_FEMALE) + .contains(this.getAvatarId()); } public Player getPlayer() { @@ -289,8 +286,8 @@ public class Avatar { } /** - * Changes the avatar's element to the target element. - * Only applies if the avatar has the element in its 'candSkillDepot's. + * Changes the avatar's element to the target element. Only applies if the avatar has the element + * in its 'candSkillDepot's. * * @param newElement The new element to change to. * @return True if the element was changed, false otherwise. @@ -300,8 +297,8 @@ public class Avatar { } /** - * Changes the avatar's element to the target element. - * Only applies if the avatar has the element in its 'candSkillDepot's. + * Changes the avatar's element to the target element. Only applies if the avatar has the element + * in its 'candSkillDepot's. * * @param elementTypeToChange The new element to change to. * @param notify Whether to notify the player of the change. diff --git a/src/main/java/emu/grasscutter/game/drop/DropSystem.java b/src/main/java/emu/grasscutter/game/drop/DropSystem.java index cefee9989..eea63cb5d 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropSystem.java +++ b/src/main/java/emu/grasscutter/game/drop/DropSystem.java @@ -18,7 +18,6 @@ import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.packet.send.PacketDropHintNotify; import emu.grasscutter.server.packet.send.PacketGadgetAutoPickDropInfoNotify; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; - import java.util.*; public final class DropSystem extends BaseGameSystem { @@ -47,7 +46,8 @@ public final class DropSystem extends BaseGameSystem { chestReward.get(i.getIndex()).add(i); } } catch (Exception ignored) { - Grasscutter.getLogger().error("Unable to load chest drop data. Please place ChestDrop.json in data folder."); + Grasscutter.getLogger() + .error("Unable to load chest drop data. Please place ChestDrop.json in data folder."); } try { @@ -59,7 +59,8 @@ public final class DropSystem extends BaseGameSystem { monsterDrop.get(i.getIndex()).add(i); } } catch (Exception ignored) { - Grasscutter.getLogger().error("Unable to load monster drop data. Please place MonsterDrop.json in data folder."); + Grasscutter.getLogger() + .error("Unable to load monster drop data. Please place MonsterDrop.json in data folder."); } } @@ -97,7 +98,8 @@ public final class DropSystem extends BaseGameSystem { List items = new ArrayList<>(); processDrop(dropData, 1, items); if (dropData.isFallToGround()) { - dropItems(items, ActionReason.MonsterDie, monster, monster.getScene().getPlayers().get(0), true); + dropItems( + items, ActionReason.MonsterDie, monster, monster.getScene().getPlayers().get(0), true); } else { for (Player p : monster.getScene().getPlayers()) { p.getInventory().addItems(items, ActionReason.MonsterDie); @@ -137,8 +139,8 @@ public final class DropSystem extends BaseGameSystem { } private void processDrop(DropTableData dropData, int count, List items) { - //TODO:Not clear on the meaning of some fields,like "dropLevel".Will ignore them. - //TODO:solve drop limits,like everydayLimit. + // TODO:Not clear on the meaning of some fields,like "dropLevel".Will ignore them. + // TODO:solve drop limits,like everydayLimit. if (count > 1) { for (int i = 0; i < count; i++) processDrop(dropData, 1, items); return; @@ -158,7 +160,7 @@ public final class DropSystem extends BaseGameSystem { if (id == 0) continue; sum += i.getWeight(); if (weight < sum) { - //win the item + // win the item int amount = calculateDropAmount(i) * count; if (amount <= 0) break; if (dropTable.containsKey(id)) { @@ -220,17 +222,25 @@ public final class DropSystem extends BaseGameSystem { /** * @param share Whether other players in the scene could see the drop items. */ - private void dropItem(GameItem item, ActionReason reason, Player player, GameEntity bornFrom, boolean share) { + private void dropItem( + GameItem item, ActionReason reason, Player player, GameEntity bornFrom, boolean share) { DropMaterialData drop = GameData.getDropMaterialDataMap().get(item.getItemId()); - if ((drop != null && drop.isAutoPick()) || (item.getItemData().getItemType() == ItemType.ITEM_VIRTUAL && item.getItemData().getGadgetId() == 0)) { + if ((drop != null && drop.isAutoPick()) + || (item.getItemData().getItemType() == ItemType.ITEM_VIRTUAL + && item.getItemData().getGadgetId() == 0)) { giveItem(item, reason, player, share); } else { - //TODO:solve share problem + // TODO:solve share problem player.getScene().addDropEntity(item, bornFrom, player, share); } } - private void dropItems(List items, ActionReason reason, GameEntity bornFrom, Player player, boolean share) { + private void dropItems( + List items, + ActionReason reason, + GameEntity bornFrom, + Player player, + boolean share) { for (var i : items) { dropItem(i, reason, player, bornFrom, share); } @@ -249,7 +259,7 @@ public final class DropSystem extends BaseGameSystem { } private void giveItems(List items, ActionReason reason, Player player, boolean share) { - //don't know whether we need PacketDropHintNotify. + // don't know whether we need PacketDropHintNotify. if (share) { for (var p : player.getScene().getPlayers()) { p.getInventory().addItems(items, reason); @@ -260,5 +270,4 @@ public final class DropSystem extends BaseGameSystem { player.sendPacket(new PacketDropHintNotify(items, player.getPosition().toProto())); } } - } diff --git a/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java b/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java index 93c88a7b5..b83bd0f48 100644 --- a/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java +++ b/src/main/java/emu/grasscutter/game/drop/DropSystemLegacy.java @@ -17,7 +17,6 @@ import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - import java.util.List; public class DropSystemLegacy extends BaseGameSystem { @@ -49,20 +48,27 @@ public class DropSystemLegacy extends BaseGameSystem { Grasscutter.getLogger().error("Unable to load drop data.", e); } } - private void addDropEntity(DropData dd, Scene dropScene, ItemData itemData, Position pos, int num, Player target) { - if (!dd.isGive() && (itemData.getItemType() != ItemType.ITEM_VIRTUAL || itemData.getGadgetId() != 0)) { + + private void addDropEntity( + DropData dd, Scene dropScene, ItemData itemData, Position pos, int num, Player target) { + if (!dd.isGive() + && (itemData.getItemType() != ItemType.ITEM_VIRTUAL || itemData.getGadgetId() != 0)) { EntityItem entity = new EntityItem(dropScene, target, itemData, pos, num, dd.isShare()); - if (!dd.isShare()) - dropScene.addEntityToSingleClient(target, entity); - else - dropScene.addEntity(entity); + if (!dd.isShare()) dropScene.addEntityToSingleClient(target, entity); + else dropScene.addEntity(entity); } else { if (target != null) { target.getInventory().addItem(new GameItem(itemData, num), ActionReason.SubfieldDrop, true); } else { - // target is null if items will be added are shared. no one could pick it up because of the combination(give + shared) + // target is null if items will be added are shared. no one could pick it up because of the + // combination(give + shared) // so it will be sent to all players' inventories directly. - dropScene.getPlayers().forEach(x -> x.getInventory().addItem(new GameItem(itemData, num), ActionReason.SubfieldDrop, true)); + dropScene + .getPlayers() + .forEach( + x -> + x.getInventory() + .addItem(new GameItem(itemData, num), ActionReason.SubfieldDrop, true)); } } } @@ -93,8 +99,7 @@ public class DropSystemLegacy extends BaseGameSystem { int id = em.getMonsterData().getId(); if (getDropData().containsKey(id)) { for (DropData dd : getDropData().get(id)) { - if (dd.isShare()) - processDrop(dd, em, null); + if (dd.isShare()) processDrop(dd, em, null); else { for (Player gp : em.getScene().getPlayers()) { processDrop(dd, em, gp); diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java index b881d65fe..270dc26ed 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java @@ -28,31 +28,46 @@ public class GadgetChest extends GadgetContent { * @return Whether we should remove the gadget. */ public boolean onInteract(Player player, GadgetInteractReq req) { - //If bigWorldScript enabled,use new drop system. + // If bigWorldScript enabled,use new drop system. if (Grasscutter.getConfig().server.game.enableScriptInBigWorld) { SceneGadget chest = getGadget().getMetaGadget(); DropSystem dropSystem = player.getServer().getDropSystem(); if (chest.boss_chest != null && chest.drop_tag != null) { - //Boss chest drop - //TODO:check for blossom chests + // Boss chest drop + // TODO:check for blossom chests if (req.getOpType() == InterOpType.INTER_OP_TYPE_START) { - //Two steps - player.sendPacket(new PacketGadgetInteractRsp(getGadget(), InteractType.INTERACT_TYPE_OPEN_CHEST, InterOpType.INTER_OP_TYPE_START)); + // Two steps + player.sendPacket( + new PacketGadgetInteractRsp( + getGadget(), + InteractType.INTERACT_TYPE_OPEN_CHEST, + InterOpType.INTER_OP_TYPE_START)); return false; } - //TODO:check for take_num.(some boss rewards can only be claimed once a week.). Handle boss respawn. - //TODO:should return Retcode.RET_RESIN_NOT_ENOUGH ? - if (player.getResinManager().useResin(chest.boss_chest.resin) && dropSystem.handleBossChestDrop(chest.drop_tag, player)) { - //Is it correct? - player.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_WORLD_BOSS_REWARD, chest.boss_chest.monster_config_id, 1); + // TODO:check for take_num.(some boss rewards can only be claimed once a week.). Handle boss + // respawn. + // TODO:should return Retcode.RET_RESIN_NOT_ENOUGH ? + if (player.getResinManager().useResin(chest.boss_chest.resin) + && dropSystem.handleBossChestDrop(chest.drop_tag, player)) { + // Is it correct? + player + .getBattlePassManager() + .triggerMission( + WatcherTriggerType.TRIGGER_WORLD_BOSS_REWARD, + chest.boss_chest.monster_config_id, + 1); getGadget().updateState(ScriptGadgetState.ChestOpened); - player.sendPacket(new PacketGadgetInteractRsp(this.getGadget(), InteractTypeOuterClass.InteractType.INTERACT_TYPE_OPEN_CHEST, InterOpType.INTER_OP_TYPE_FINISH)); + player.sendPacket( + new PacketGadgetInteractRsp( + this.getGadget(), + InteractTypeOuterClass.InteractType.INTERACT_TYPE_OPEN_CHEST, + InterOpType.INTER_OP_TYPE_FINISH)); return true; } - //if failed,fallback to legacy drop system. + // if failed,fallback to legacy drop system. } else { - //Normal chest drop - //only the owner of the world can open chests. + // Normal chest drop + // only the owner of the world can open chests. if (player != player.getWorld().getHost()) return false; boolean status = false; if (chest.drop_tag != null) { @@ -62,31 +77,56 @@ public class GadgetChest extends GadgetContent { } if (status) { getGadget().updateState(ScriptGadgetState.ChestOpened); - player.sendPacket(new PacketGadgetInteractRsp(getGadget(), InteractType.INTERACT_TYPE_OPEN_CHEST, InterOpType.INTER_OP_TYPE_FINISH)); - player.sendPacket(new PacketWorldChestOpenNotify(getGadget().getGroupId(), player.getSceneId(), chest.config_id)); + player.sendPacket( + new PacketGadgetInteractRsp( + getGadget(), + InteractType.INTERACT_TYPE_OPEN_CHEST, + InterOpType.INTER_OP_TYPE_FINISH)); + player.sendPacket( + new PacketWorldChestOpenNotify( + getGadget().getGroupId(), player.getSceneId(), chest.config_id)); return true; } - //if failed,fallback to legacy drop system. + // if failed,fallback to legacy drop system. } - Grasscutter.getLogger().warn("Can not solve chest drop: chest_drop_id = {} , drop_tag = {}.Fallback to legacy drop system.", chest.chest_drop_id, chest.drop_tag); + Grasscutter.getLogger() + .warn( + "Can not solve chest drop: chest_drop_id = {} , drop_tag = {}.Fallback to legacy drop system.", + chest.chest_drop_id, + chest.drop_tag); } - //Legacy chest drop system - var chestInteractHandlerMap = getGadget().getScene().getWorld().getServer().getWorldDataSystem().getChestInteractHandlerMap(); + // Legacy chest drop system + var chestInteractHandlerMap = + getGadget() + .getScene() + .getWorld() + .getServer() + .getWorldDataSystem() + .getChestInteractHandlerMap(); var handler = chestInteractHandlerMap.get(getGadget().getGadgetData().getJsonName()); if (handler == null) { - Grasscutter.getLogger().warn("Could not found the handler of this type of Chests {}", getGadget().getGadgetData().getJsonName()); + Grasscutter.getLogger() + .warn( + "Could not found the handler of this type of Chests {}", + getGadget().getGadgetData().getJsonName()); return false; } if (req.getOpType() == InterOpType.INTER_OP_TYPE_START && handler.isTwoStep()) { - player.sendPacket(new PacketGadgetInteractRsp(getGadget(), InteractType.INTERACT_TYPE_OPEN_CHEST, InterOpType.INTER_OP_TYPE_START)); + player.sendPacket( + new PacketGadgetInteractRsp( + getGadget(), InteractType.INTERACT_TYPE_OPEN_CHEST, InterOpType.INTER_OP_TYPE_START)); return false; } else { boolean success; if (handler instanceof BossChestInteractHandler bossChestInteractHandler) { - success = bossChestInteractHandler.onInteract(this, player, - req.getResinCostType() == ResinCostTypeOuterClass.ResinCostType.RESIN_COST_TYPE_CONDENSE); + success = + bossChestInteractHandler.onInteract( + this, + player, + req.getResinCostType() + == ResinCostTypeOuterClass.ResinCostType.RESIN_COST_TYPE_CONDENSE); } else { success = handler.onInteract(this, player); } @@ -95,7 +135,11 @@ public class GadgetChest extends GadgetContent { } getGadget().updateState(ScriptGadgetState.ChestOpened); - player.sendPacket(new PacketGadgetInteractRsp(this.getGadget(), InteractTypeOuterClass.InteractType.INTERACT_TYPE_OPEN_CHEST, InterOpType.INTER_OP_TYPE_FINISH)); + player.sendPacket( + new PacketGadgetInteractRsp( + this.getGadget(), + InteractTypeOuterClass.InteractType.INTERACT_TYPE_OPEN_CHEST, + InterOpType.INTER_OP_TYPE_FINISH)); return true; } @@ -110,13 +154,13 @@ public class GadgetChest extends GadgetContent { if (bossChest != null) { var players = getGadget().getScene().getPlayers().stream().map(Player::getUid).toList(); - gadgetInfo.setBossChest(BossChestInfo.newBuilder() - .setMonsterConfigId(bossChest.monster_config_id) - .setResin(bossChest.resin) - .addAllQualifyUidList(players) - .addAllRemainUidList(players) - .build()); + gadgetInfo.setBossChest( + BossChestInfo.newBuilder() + .setMonsterConfigId(bossChest.monster_config_id) + .setResin(bossChest.resin) + .addAllQualifyUidList(players) + .addAllRemainUidList(players) + .build()); } - } } diff --git a/src/main/java/emu/grasscutter/game/managers/ResinManager.java b/src/main/java/emu/grasscutter/game/managers/ResinManager.java index 6e865b525..c46bc680e 100644 --- a/src/main/java/emu/grasscutter/game/managers/ResinManager.java +++ b/src/main/java/emu/grasscutter/game/managers/ResinManager.java @@ -1,5 +1,7 @@ package emu.grasscutter.game.managers; +import static emu.grasscutter.config.Configuration.GAME_OPTIONS; + import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.BasePlayerManager; import emu.grasscutter.game.player.Player; @@ -11,12 +13,10 @@ import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import emu.grasscutter.server.packet.send.PacketResinChangeNotify; import emu.grasscutter.utils.Utils; -import static emu.grasscutter.config.Configuration.GAME_OPTIONS; - public class ResinManager extends BasePlayerManager { public static final int MAX_RESIN_BUYING_COUNT = 6; public static final int AMOUNT_TO_ADD = 60; - public static final int[] HCOIN_NUM_TO_BUY_RESIN = new int[]{50, 100, 100, 150, 200, 200}; + public static final int[] HCOIN_NUM_TO_BUY_RESIN = new int[] {50, 100, 100, 150, 200, 200}; public ResinManager(Player player) { super(player); @@ -53,7 +53,10 @@ public class ResinManager extends BasePlayerManager { this.player.sendPacket(new PacketResinChangeNotify(this.player)); // Battle Pass trigger - this.player.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_COST_MATERIAL, 106, amount); // Resin item id = 106 + this.player + .getBattlePassManager() + .triggerMission( + WatcherTriggerType.TRIGGER_COST_MATERIAL, 106, amount); // Resin item id = 106 return true; } @@ -110,7 +113,11 @@ public class ResinManager extends BasePlayerManager { // Calculate how much resin we need to refill and update player. // Note that this can be more than one in case the player // logged off with uncapped resin and is now logging in again. - int recharge = 1 + (int)((currentTime - this.player.getNextResinRefresh()) / GAME_OPTIONS.resinOptions.rechargeTime); + int recharge = + 1 + + (int) + ((currentTime - this.player.getNextResinRefresh()) + / GAME_OPTIONS.resinOptions.rechargeTime); int newResin = Math.min(GAME_OPTIONS.resinOptions.cap, currentResin + recharge); int resinChange = newResin - currentResin; @@ -120,9 +127,9 @@ public class ResinManager extends BasePlayerManager { // Set to zero to disable recharge (because on/over cap.) if (newResin >= GAME_OPTIONS.resinOptions.cap) { this.player.setNextResinRefresh(0); - } - else { - int nextRecharge = this.player.getNextResinRefresh() + resinChange * GAME_OPTIONS.resinOptions.rechargeTime; + } else { + int nextRecharge = + this.player.getNextResinRefresh() + resinChange * GAME_OPTIONS.resinOptions.rechargeTime; this.player.setNextResinRefresh(nextRecharge); } @@ -158,7 +165,10 @@ public class ResinManager extends BasePlayerManager { return RetcodeOuterClass.Retcode.RET_RESIN_BOUGHT_COUNT_EXCEEDED_VALUE; } - var res = this.player.getInventory().payItem(201, HCOIN_NUM_TO_BUY_RESIN[this.player.getResinBuyCount()]); + var res = + this.player + .getInventory() + .payItem(201, HCOIN_NUM_TO_BUY_RESIN[this.player.getResinBuyCount()]); if (!res) { return RetcodeOuterClass.Retcode.RET_HCOIN_NOT_ENOUGH_VALUE; } @@ -166,7 +176,8 @@ public class ResinManager extends BasePlayerManager { this.player.setResinBuyCount(this.player.getResinBuyCount() + 1); this.player.setProperty(PlayerProperty.PROP_PLAYER_WAIT_SUB_HCOIN, 0); this.addResin(AMOUNT_TO_ADD); - this.player.sendPacket(new PacketItemAddHintNotify(new GameItem(106, AMOUNT_TO_ADD), ActionReason.BuyResin)); + this.player.sendPacket( + new PacketItemAddHintNotify(new GameItem(106, AMOUNT_TO_ADD), ActionReason.BuyResin)); return 0; } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddItem.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddItem.java index 0d36d486f..dd874138c 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddItem.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddItem.java @@ -15,11 +15,15 @@ public class ItemUseAddItem extends ItemUseInt { super(useParam); try { this.count = Integer.parseInt(useParam[1]); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) {} + } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) { + } } @Override public boolean useItem(UseItemParams params) { - return params.player.getInventory().addItem(this.i, this.count * params.count, ActionReason.PlayerUseItem); + return params + .player + .getInventory() + .addItem(this.i, this.count * params.count, ActionReason.PlayerUseItem); } } diff --git a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java index 0d812d5a8..74c6b5624 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java @@ -303,7 +303,15 @@ public class GameMainQuest { return true; } - public boolean hasTeleportPostion(int subId, List posAndRot) { + /** + * Checks if the quest has a teleport position. Returns true if it does & adds the target position + * & rotation to the list. + * + * @param subId The sub-quest ID. + * @param posAndRot A list which will contain the position & rotation if the quest has a teleport. + * @return True if the quest has a teleport position. False otherwise. + */ + public boolean hasTeleportPosition(int subId, List posAndRot) { TeleportData questTransmit = GameData.getTeleportDataMap().get(subId); if (questTransmit == null) return false; @@ -338,7 +346,7 @@ public class GameMainQuest { 1, new Position( transmitPosRot.get(0), transmitPosRot.get(1), transmitPosRot.get(2))); // rotation - Grasscutter.getLogger().info("Succesfully loaded teleport data for subQuest {}", subId); + Grasscutter.getLogger().debug("Successfully loaded teleport data for sub-quest {}.", subId); return true; } diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index 09840dec2..6d5545925 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -20,12 +20,11 @@ import emu.grasscutter.server.packet.send.PacketChapterStateNotify; import emu.grasscutter.server.packet.send.PacketDelQuestNotify; import emu.grasscutter.server.packet.send.PacketQuestListUpdateNotify; import emu.grasscutter.utils.Utils; +import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.script.Bindings; - -import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; import lombok.Getter; import lombok.Setter; import lombok.val; @@ -227,8 +226,9 @@ public class GameQuest { } // Give items for completing the quest. - this.getQuestData().getGainItems().forEach(item -> - this.getOwner().getInventory().addItem(item, ActionReason.QuestItem)); + this.getQuestData() + .getGainItems() + .forEach(item -> this.getOwner().getInventory().addItem(item, ActionReason.QuestItem)); this.save(); Grasscutter.getLogger().debug("Quest {} was completed.", subQuestId); @@ -283,23 +283,26 @@ public class GameQuest { } /** - * @return A list of dungeon IDs associated with the quest's 'QUEST_CONTENT_ENTER_DUNGEON' triggers. - * The first element of the pair is the dungeon ID. - * The second element of the pair is the dungeon's scene point. + * @return A list of dungeon IDs associated with the quest's 'QUEST_CONTENT_ENTER_DUNGEON' + * triggers. The first element of the pair is the dungeon ID. The second element of the pair + * is the dungeon's scene point. */ public List getDungeonIds() { - var conditions = this.getQuestData().getFinishCond().stream() - .filter(cond -> cond.getType() == QuestContent.QUEST_CONTENT_ENTER_DUNGEON) - .toList(); + var conditions = + this.getQuestData().getFinishCond().stream() + .filter(cond -> cond.getType() == QuestContent.QUEST_CONTENT_ENTER_DUNGEON) + .toList(); return conditions.stream() - .map(condition -> { - var params = condition.getParam(); - // The first parameter is the ID of the dungeon. - // The second parameter is the dungeon entry's scene point. - // ex. [1, 1] = dungeon ID 1, scene point 1 or 'KaeyaDungeon'. - return new IntIntImmutablePair(params[0], params[1]); - }).toList(); + .map( + condition -> { + var params = condition.getParam(); + // The first parameter is the ID of the dungeon. + // The second parameter is the dungeon entry's scene point. + // ex. [1, 1] = dungeon ID 1, scene point 1 or 'KaeyaDungeon'. + return new IntIntImmutablePair(params[0], params[1]); + }) + .toList(); } public void save() { diff --git a/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java b/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java index 3db2ce300..1cdae83b6 100644 --- a/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java +++ b/src/main/java/emu/grasscutter/game/quest/exec/ExecNotifyGroupLua.java @@ -52,7 +52,9 @@ public class ExecNotifyGroupLua extends QuestExecHandler { quest.getState() == QuestState.QUEST_STATE_FINISHED ? EventType.EVENT_QUEST_FINISH : EventType.EVENT_QUEST_START; - scriptManager.callEvent(new ScriptArgs(groupId, eventType, quest.getSubQuestId()).setEventSource(String.valueOf(quest.getSubQuestId()))); + scriptManager.callEvent( + new ScriptArgs(groupId, eventType, quest.getSubQuestId()) + .setEventSource(String.valueOf(quest.getSubQuestId()))); }); return true; diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 68963cf36..10594cb03 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -40,17 +40,11 @@ import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.KahnsSort; import emu.grasscutter.utils.Position; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import lombok.Getter; -import lombok.Setter; -import lombok.val; - -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; import javax.annotation.Nullable; - import lombok.Getter; import lombok.Setter; import lombok.val; @@ -311,8 +305,7 @@ public final class Scene { // TODO:optimize EntityItem.java. Maybe we should make other players can't see // the ItemEntity. ItemData itemData = GameData.getItemDataMap().get(item.getItemId()); - if (itemData == null) - return; + if (itemData == null) return; if (itemData.isEquip()) { float range = (1.5f + (.05f * item.getCount())); for (int j = 0; j < item.getCount(); j++) { @@ -321,11 +314,16 @@ public final class Scene { addEntity(entity); } } else { - EntityItem entity = new EntityItem(this, player, itemData, bornForm.getPosition().clone().addY(0.5f), - item.getCount(), share); + EntityItem entity = + new EntityItem( + this, + player, + itemData, + bornForm.getPosition().clone().addY(0.5f), + item.getCount(), + share); addEntity(entity); } - } public void addEntities(Collection entities) { @@ -333,7 +331,7 @@ public final class Scene { } public synchronized void addEntities( - Collection entities, VisionType visionType) { + Collection entities, VisionType visionType) { if (entities == null || entities.isEmpty()) { return; } @@ -448,8 +446,13 @@ public final class Scene { // Reward drop var world = this.getWorld(); if (target instanceof EntityMonster monster && this.getSceneType() != SceneType.SCENE_DUNGEON) { - if (monster.getMetaMonster() != null && !world.getServer().getDropSystem().handleMonsterDrop(monster)) { - Grasscutter.getLogger().debug("Can not solve monster drop: drop_id = {}, drop_tag = {}. Falling back to legacy drop system.", monster.getMetaMonster().drop_id, monster.getMetaMonster().drop_tag); + if (monster.getMetaMonster() != null + && !world.getServer().getDropSystem().handleMonsterDrop(monster)) { + Grasscutter.getLogger() + .debug( + "Can not solve monster drop: drop_id = {}, drop_tag = {}. Falling back to legacy drop system.", + monster.getMetaMonster().drop_id, + monster.getMetaMonster().drop_tag); getWorld().getServer().getDropSystemLegacy().callDrop(monster); } } diff --git a/src/main/java/emu/grasscutter/game/world/World.java b/src/main/java/emu/grasscutter/game/world/World.java index d31c8e361..677b20532 100644 --- a/src/main/java/emu/grasscutter/game/world/World.java +++ b/src/main/java/emu/grasscutter/game/world/World.java @@ -279,10 +279,10 @@ public class World implements Iterable { val sceneData = GameData.getSceneDataMap().get(sceneId); if (dungeonData != null) { - teleportProps.teleportTo(dungeonData.getStartPosition()) - .teleportRot(dungeonData.getStartRotation()); - teleportProps.enterType(EnterType.ENTER_TYPE_DUNGEON) - .enterReason(EnterReason.DungeonEnter); + teleportProps + .teleportTo(dungeonData.getStartPosition()) + .teleportRot(dungeonData.getStartRotation()); + teleportProps.enterType(EnterType.ENTER_TYPE_DUNGEON).enterReason(EnterReason.DungeonEnter); } else if (player.getSceneId() == sceneId) { teleportProps.enterType(EnterType.ENTER_TYPE_GOTO); } else if (sceneData != null && sceneData.getSceneType() == SceneType.SCENE_HOME_WORLD) { diff --git a/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java b/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java index ee70af00b..db71338ea 100644 --- a/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/EntityControllerScriptManager.java @@ -8,8 +8,6 @@ import java.io.IOException; import java.nio.file.Files; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import javax.script.Bindings; -import javax.script.CompiledScript; import lombok.val; public class EntityControllerScriptManager { @@ -21,23 +19,23 @@ public class EntityControllerScriptManager { private static void cacheGadgetControllers() { try (var stream = Files.newDirectoryStream(getScriptPath("Gadget/"), "*.lua")) { - stream.forEach(path -> { - val fileName = path.getFileName().toString(); - if (!fileName.endsWith(".lua")) return; + stream.forEach( + path -> { + val fileName = path.getFileName().toString(); + if (!fileName.endsWith(".lua")) return; - val controllerName = fileName.substring(0, fileName.length() - 4); - var cs = ScriptLoader.getScript("Gadget/" + fileName); - var bindings = ScriptLoader.getEngine().createBindings(); - if (cs == null) return; + val controllerName = fileName.substring(0, fileName.length() - 4); + var cs = ScriptLoader.getScript("Gadget/" + fileName); + var bindings = ScriptLoader.getEngine().createBindings(); + if (cs == null) return; - try { - cs.eval(bindings); - gadgetController.put(controllerName, new EntityController(cs, bindings)); - } catch (Throwable e) { - Grasscutter.getLogger() - .error("Error while loading gadget controller: {}.", fileName); - } - }); + try { + cs.eval(bindings); + gadgetController.put(controllerName, new EntityController(cs, bindings)); + } catch (Throwable e) { + Grasscutter.getLogger().error("Error while loading gadget controller: {}.", fileName); + } + }); Grasscutter.getLogger().debug("Loaded {} gadget controllers", gadgetController.size()); } catch (IOException e) { Grasscutter.getLogger().error("Error loading gadget controller Lua scripts."); diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java index 46ba562e9..007fe7b9d 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java @@ -21,11 +21,13 @@ public class SceneGadget extends SceneObject { public SceneBossChest boss_chest; public int interact_id; /** - * Note: this field indicates whether the gadget should disappear permanently. - * For example, if isOneOff=true, like most chests, it will disappear permanently after interacted. - * If isOneOff=false, like investigation points, it will disappear temporarily, and appear again in next big world resource refresh routine. + * Note: this field indicates whether the gadget should disappear permanently. For example, if + * isOneOff=true, like most chests, it will disappear permanently after interacted. If + * isOneOff=false, like investigation points, it will disappear temporarily, and appear again in + * next big world resource refresh routine. */ public boolean isOneoff; + public int area_id; public int draft_id; public int route_id; diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index c69d1bf77..7870aeee7 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -1,5 +1,8 @@ package emu.grasscutter.server.game; +import static emu.grasscutter.config.Configuration.GAME_INFO; +import static emu.grasscutter.utils.Language.translate; + import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.database.DatabaseHelper; @@ -34,18 +37,14 @@ import emu.grasscutter.server.event.internal.ServerStopEvent; import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.server.scheduler.ServerTaskScheduler; import emu.grasscutter.task.TaskMap; -import kcp.highway.ChannelConfig; -import kcp.highway.KcpServer; -import lombok.Getter; - import java.net.InetSocketAddress; import java.time.Instant; import java.time.OffsetDateTime; import java.util.*; import java.util.concurrent.ConcurrentHashMap; - -import static emu.grasscutter.config.Configuration.GAME_INFO; -import static emu.grasscutter.utils.Language.translate; +import kcp.highway.ChannelConfig; +import kcp.highway.KcpServer; +import lombok.Getter; @Getter public final class GameServer extends KcpServer { diff --git a/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java b/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java index 60517aded..0c7a2914a 100644 --- a/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java +++ b/src/main/java/emu/grasscutter/server/http/dispatch/RegionHandler.java @@ -1,13 +1,15 @@ package emu.grasscutter.server.http.dispatch; +import static emu.grasscutter.config.Configuration.*; + import com.google.protobuf.ByteString; import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerRunMode; -import emu.grasscutter.net.proto.QueryRegionListHttpRspOuterClass.QueryRegionListHttpRsp; import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp; -import emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo; +import emu.grasscutter.net.proto.QueryRegionListHttpRspOuterClass.QueryRegionListHttpRsp; import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo; +import emu.grasscutter.net.proto.RegionSimpleInfoOuterClass.RegionSimpleInfo; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.StopServerInfoOuterClass.StopServerInfo; import emu.grasscutter.server.event.dispatch.QueryAllRegionsEvent; @@ -18,23 +20,13 @@ import emu.grasscutter.utils.Crypto; import emu.grasscutter.utils.Utils; import io.javalin.Javalin; import io.javalin.http.Context; - import java.time.Instant; -import javax.crypto.Cipher; -import java.io.ByteArrayOutputStream; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.security.Signature; import java.util.regex.Pattern; - import org.slf4j.Logger; -import static emu.grasscutter.config.Configuration.*; -import static emu.grasscutter.utils.Language.translate; - -/** - * Handles requests related to region queries. - */ +/** Handles requests related to region queries. */ public final class RegionHandler implements Router { private static final Map regions = new ConcurrentHashMap<>(); private static String regionListResponse; @@ -48,13 +40,15 @@ public final class RegionHandler implements Router { } } - /** - * Configures region data according to configuration. - */ + /** Configures region data according to configuration. */ private void initialize() { - String dispatchDomain = "http" + (HTTP_ENCRYPTION.useInRouting ? "s" : "") + "://" - + lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) + ":" - + lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort); + String dispatchDomain = + "http" + + (HTTP_ENCRYPTION.useInRouting ? "s" : "") + + "://" + + lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) + + ":" + + lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort); // Create regions. List servers = new ArrayList<>(); @@ -62,61 +56,84 @@ public final class RegionHandler implements Router { var configuredRegions = new ArrayList<>(List.of(DISPATCH_INFO.regions)); if (SERVER.runMode != ServerRunMode.HYBRID && configuredRegions.size() == 0) { - Grasscutter.getLogger().error("[Dispatch] There are no game servers available. Exiting due to unplayable state."); + Grasscutter.getLogger() + .error( + "[Dispatch] There are no game servers available. Exiting due to unplayable state."); System.exit(1); } else if (configuredRegions.size() == 0) - configuredRegions.add(new Region("os_usa", DISPATCH_INFO.defaultName, - lr(GAME_INFO.accessAddress, GAME_INFO.bindAddress), - lr(GAME_INFO.accessPort, GAME_INFO.bindPort))); + configuredRegions.add( + new Region( + "os_usa", + DISPATCH_INFO.defaultName, + lr(GAME_INFO.accessAddress, GAME_INFO.bindAddress), + lr(GAME_INFO.accessPort, GAME_INFO.bindPort))); - configuredRegions.forEach(region -> { - if (usedNames.contains(region.Name)) { - Grasscutter.getLogger().error("Region name already in use."); - return; - } + configuredRegions.forEach( + region -> { + if (usedNames.contains(region.Name)) { + Grasscutter.getLogger().error("Region name already in use."); + return; + } - // Create a region identifier. - var identifier = RegionSimpleInfo.newBuilder() - .setName(region.Name).setTitle(region.Title).setType("DEV_PUBLIC") - .setDispatchUrl(dispatchDomain + "/query_cur_region/" + region.Name) - .build(); - usedNames.add(region.Name); servers.add(identifier); + // Create a region identifier. + var identifier = + RegionSimpleInfo.newBuilder() + .setName(region.Name) + .setTitle(region.Title) + .setType("DEV_PUBLIC") + .setDispatchUrl(dispatchDomain + "/query_cur_region/" + region.Name) + .build(); + usedNames.add(region.Name); + servers.add(identifier); - // Create a region info object. - var regionInfo = RegionInfo.newBuilder() - .setGateserverIp(region.Ip).setGateserverPort(region.Port) - .setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) - .build(); - // Create an updated region query. - var updatedQuery = QueryCurrRegionHttpRsp.newBuilder().setRegionInfo(regionInfo).build(); - regions.put(region.Name, new RegionData(updatedQuery, Utils.base64Encode(updatedQuery.toByteString().toByteArray()))); - }); + // Create a region info object. + var regionInfo = + RegionInfo.newBuilder() + .setGateserverIp(region.Ip) + .setGateserverPort(region.Port) + .setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) + .build(); + // Create an updated region query. + var updatedQuery = QueryCurrRegionHttpRsp.newBuilder().setRegionInfo(regionInfo).build(); + regions.put( + region.Name, + new RegionData( + updatedQuery, Utils.base64Encode(updatedQuery.toByteString().toByteArray()))); + }); // Create a config object. - byte[] customConfig = "{\"sdkenv\":\"2\",\"checkdevice\":\"false\",\"loadPatch\":\"false\",\"showexception\":\"false\",\"regionConfig\":\"pm|fk|add\",\"downloadMode\":\"0\"}".getBytes(); + byte[] customConfig = + "{\"sdkenv\":\"2\",\"checkdevice\":\"false\",\"loadPatch\":\"false\",\"showexception\":\"false\",\"regionConfig\":\"pm|fk|add\",\"downloadMode\":\"0\"}" + .getBytes(); Crypto.xor(customConfig, Crypto.DISPATCH_KEY); // XOR the config with the key. // Create an updated region list. - QueryRegionListHttpRsp updatedRegionList = QueryRegionListHttpRsp.newBuilder() - .addAllRegionList(servers) - .setClientSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) - .setClientCustomConfigEncrypted(ByteString.copyFrom(customConfig)) - .setEnableLoginPc(true).build(); + QueryRegionListHttpRsp updatedRegionList = + QueryRegionListHttpRsp.newBuilder() + .addAllRegionList(servers) + .setClientSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) + .setClientCustomConfigEncrypted(ByteString.copyFrom(customConfig)) + .setEnableLoginPc(true) + .build(); // Set the region list response. regionListResponse = Utils.base64Encode(updatedRegionList.toByteString().toByteArray()); // CN // Create a config object. - byte[] customConfigcn = "{\"sdkenv\":\"0\",\"checkdevice\":\"true\",\"loadPatch\":\"false\",\"showexception\":\"false\",\"regionConfig\":\"pm|fk|add\",\"downloadMode\":\"0\"}".getBytes(); + byte[] customConfigcn = + "{\"sdkenv\":\"0\",\"checkdevice\":\"true\",\"loadPatch\":\"false\",\"showexception\":\"false\",\"regionConfig\":\"pm|fk|add\",\"downloadMode\":\"0\"}" + .getBytes(); Crypto.xor(customConfigcn, Crypto.DISPATCH_KEY); // XOR the config with the key. // Create an updated region list. - QueryRegionListHttpRsp updatedRegionListcn = QueryRegionListHttpRsp.newBuilder() - .addAllRegionList(servers) - .setClientSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) - .setClientCustomConfigEncrypted(ByteString.copyFrom(customConfigcn)) - .setEnableLoginPc(true).build(); + QueryRegionListHttpRsp updatedRegionListcn = + QueryRegionListHttpRsp.newBuilder() + .addAllRegionList(servers) + .setClientSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) + .setClientCustomConfigEncrypted(ByteString.copyFrom(customConfigcn)) + .setEnableLoginPc(true) + .build(); // Set the region list response. regionListResponsecn = Utils.base64Encode(updatedRegionListcn.toByteString().toByteArray()); @@ -143,7 +160,8 @@ public final class RegionHandler implements Router { String platformName = ctx.queryParam("platform"); // Determine the region list to use based on the version and platform. - if ("CNRELiOS".equals(versionCode) || "CNRELWin".equals(versionCode) + if ("CNRELiOS".equals(versionCode) + || "CNRELWin".equals(versionCode) || "CNRELAndroid".equals(versionCode)) { // Use the CN region list. QueryAllRegionsEvent event = new QueryAllRegionsEvent(regionListResponsecn); @@ -152,7 +170,8 @@ public final class RegionHandler implements Router { // Respond with the event result. ctx.result(event.getRegionList()); - } else if ("OSRELiOS".equals(versionCode) || "OSRELWin".equals(versionCode) + } else if ("OSRELiOS".equals(versionCode) + || "OSRELWin".equals(versionCode) || "OSRELAndroid".equals(versionCode)) { // Use the OS region list. QueryAllRegionsEvent event = new QueryAllRegionsEvent(regionListResponse); @@ -187,7 +206,8 @@ public final class RegionHandler implements Router { ctx.result(event.getRegionList()); } // Log the request to the console. - Grasscutter.getLogger().info(String.format("[Dispatch] Client %s request: query_region_list", ctx.ip())); + Grasscutter.getLogger() + .info(String.format("[Dispatch] Client %s request: query_region_list", ctx.ip())); } /** @@ -202,39 +222,53 @@ public final class RegionHandler implements Router { // Get region data. String regionData = "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw=="; if (ctx.queryParamMap().values().size() > 0) { - if (region != null) - regionData = region.getBase64(); + if (region != null) regionData = region.getBase64(); } String clientVersion = versionName.replaceAll(Pattern.compile("[a-zA-Z]").pattern(), ""); String[] versionCode = clientVersion.split("\\."); int versionMajor = Integer.parseInt(versionCode[0]); int versionMinor = Integer.parseInt(versionCode[1]); - int versionFix = Integer.parseInt(versionCode[2]); + int versionFix = Integer.parseInt(versionCode[2]); - if (versionMajor >= 3 || (versionMajor == 2 && versionMinor == 7 && versionFix >= 50) || (versionMajor == 2 && versionMinor == 8)) { + if (versionMajor >= 3 + || (versionMajor == 2 && versionMinor == 7 && versionFix >= 50) + || (versionMajor == 2 && versionMinor == 8)) { try { - QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); event.call(); + QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); + event.call(); String key_id = ctx.queryParam("key_id"); - if (!clientVersion.equals(GameConstants.VERSION)) { // Reject clients when there is a version mismatch + if (!clientVersion.equals( + GameConstants.VERSION)) { // Reject clients when there is a version mismatch boolean updateClient = GameConstants.VERSION.compareTo(clientVersion) > 0; - QueryCurrRegionHttpRsp rsp = QueryCurrRegionHttpRsp.newBuilder() - .setRetcode(Retcode.RET_STOP_SERVER_VALUE) - .setMsg("Connection Failed!") - .setRegionInfo(RegionInfo.newBuilder()) - .setStopServer(StopServerInfo.newBuilder() - .setUrl("https://discord.gg/grasscutters") - .setStopBeginTime((int) Instant.now().getEpochSecond()) - .setStopEndTime((int) Instant.now().getEpochSecond()*2) - .setContentMsg(updateClient ? "\nVersion mismatch outdated client! \n\nServer version: %s\nClient version: %s".formatted(GameConstants.VERSION, clientVersion) : "\nVersion mismatch outdated server! \n\nServer version: %s\nClient version: %s".formatted(GameConstants.VERSION, clientVersion)) - .build()) - .buildPartial(); + QueryCurrRegionHttpRsp rsp = + QueryCurrRegionHttpRsp.newBuilder() + .setRetcode(Retcode.RET_STOP_SERVER_VALUE) + .setMsg("Connection Failed!") + .setRegionInfo(RegionInfo.newBuilder()) + .setStopServer( + StopServerInfo.newBuilder() + .setUrl("https://discord.gg/grasscutters") + .setStopBeginTime((int) Instant.now().getEpochSecond()) + .setStopEndTime((int) Instant.now().getEpochSecond() * 2) + .setContentMsg( + updateClient + ? "\nVersion mismatch outdated client! \n\nServer version: %s\nClient version: %s" + .formatted(GameConstants.VERSION, clientVersion) + : "\nVersion mismatch outdated server! \n\nServer version: %s\nClient version: %s" + .formatted(GameConstants.VERSION, clientVersion)) + .build()) + .buildPartial(); - Grasscutter.getLogger().info(String.format("Connection denied for %s due to %s", ctx.ip(), updateClient ? "outdated client!" : "outdated server!")); + Grasscutter.getLogger() + .info( + String.format( + "Connection denied for %s due to %s", + ctx.ip(), updateClient ? "outdated client!" : "outdated server!")); ctx.json(Crypto.encryptAndSignRegionData(rsp.toByteArray(), key_id)); return; @@ -251,28 +285,25 @@ public final class RegionHandler implements Router { return; } - var regionInfo = Utils.base64Decode(event.getRegionInfo()); ctx.json(Crypto.encryptAndSignRegionData(regionInfo, key_id)); - } - catch (Exception e) { + } catch (Exception e) { Grasscutter.getLogger().error("An error occurred while handling query_cur_region.", e); } - } - else { + } else { // Invoke event. - QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); event.call(); + QueryCurrentRegionEvent event = new QueryCurrentRegionEvent(regionData); + event.call(); // Respond with event result. ctx.result(event.getRegionInfo()); } // Log to console. - Grasscutter.getLogger().info(String.format("Client %s request: query_cur_region/%s", ctx.ip(), regionName)); + Grasscutter.getLogger() + .info(String.format("Client %s request: query_cur_region/%s", ctx.ip(), regionName)); } - /** - * Region data container. - */ + /** Region data container. */ public static class RegionData { private final QueryCurrRegionHttpRsp regionQuery; private final String base64; @@ -293,6 +324,7 @@ public final class RegionHandler implements Router { /** * Gets the current region query. + * * @return A {@link QueryCurrRegionHttpRsp} object. */ public static QueryCurrRegionHttpRsp getCurrentRegion() { diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java index 2866440b0..d5f5b59a8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeGameTimeReq.java @@ -15,6 +15,8 @@ public class HandlerChangeGameTimeReq extends PacketHandler { var req = ChangeGameTimeReq.parseFrom(payload); session.getPlayer().getWorld().changeTime(req.getGameTime(), req.getExtraDays()); - session.getPlayer().sendPacket(new PacketChangeGameTimeRsp(session.getPlayer(), req.getExtraDays())); + session + .getPlayer() + .sendPacket(new PacketChangeGameTimeRsp(session.getPlayer(), req.getExtraDays())); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java index 2b92a919c..9bdff120c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java @@ -94,8 +94,10 @@ public class HandlerCombatInvocationsNotify extends PacketHandler { } } - // as long as one of these two packets be forwarded to client, the animation of avatar will be interrupted - if (motionState == MotionState.MOTION_STATE_NOTIFY || motionState == MotionState.MOTION_STATE_FIGHT) { + // as long as one of these two packets be forwarded to client, the animation of avatar + // will be interrupted + if (motionState == MotionState.MOTION_STATE_NOTIFY + || motionState == MotionState.MOTION_STATE_FIGHT) { continue; } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonEntryInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonEntryInfoReq.java index 0c18c4a56..601e31a51 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonEntryInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDungeonEntryInfoReq.java @@ -13,6 +13,9 @@ public class HandlerDungeonEntryInfoReq extends PacketHandler { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { DungeonEntryInfoReq req = DungeonEntryInfoReq.parseFrom(payload); - session.getServer().getDungeonSystem().sendEntryInfoFor(session.getPlayer(), req.getPointId(), req.getSceneId()); + session + .getServer() + .getDungeonSystem() + .sendEntryInfoFor(session.getPlayer(), req.getPointId(), req.getSceneId()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerEnterDungeonReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerEnterDungeonReq.java index 5f4056d04..73c12e1ef 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerEnterDungeonReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerEnterDungeonReq.java @@ -15,12 +15,13 @@ public class HandlerPlayerEnterDungeonReq extends PacketHandler { // Auto template PlayerEnterDungeonReq req = PlayerEnterDungeonReq.parseFrom(payload); - var success = session - .getServer() - .getDungeonSystem() - .enterDungeon(session.getPlayer(), req.getPointId(), req.getDungeonId()); + var success = + session + .getServer() + .getDungeonSystem() + .enterDungeon(session.getPlayer(), req.getPointId(), req.getDungeonId()); session - .getPlayer() - .sendPacket(new PacketPlayerEnterDungeonRsp(req.getPointId(), req.getDungeonId(), success)); + .getPlayer() + .sendPacket(new PacketPlayerEnterDungeonRsp(req.getPointId(), req.getDungeonId(), success)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java index 8dcf92aef..6339003cc 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java @@ -1,6 +1,5 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; @@ -17,8 +16,9 @@ public class HandlerPostEnterSceneReq extends PacketHandler { var scene = player.getScene(); var questManager = player.getQuestManager(); - switch (session.getPlayer().getScene().getSceneType()){ - case SCENE_ROOM -> questManager.queueEvent(QuestContent.QUEST_CONTENT_ENTER_ROOM, scene.getId(), 0); + switch (session.getPlayer().getScene().getSceneType()) { + case SCENE_ROOM -> questManager.queueEvent( + QuestContent.QUEST_CONTENT_ENTER_ROOM, scene.getId(), 0); case SCENE_WORLD -> { questManager.queueEvent(QuestContent.QUEST_CONTENT_ENTER_MY_WORLD, scene.getId()); questManager.queueEvent(QuestContent.QUEST_CONTENT_ENTER_MY_WORLD_SCENE, scene.getId()); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java index 23854b74d..b745ebb77 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestTransmitReq.java @@ -1,7 +1,6 @@ package emu.grasscutter.server.packet.recv; import emu.grasscutter.data.GameData; -import emu.grasscutter.game.quest.GameMainQuest; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; @@ -10,21 +9,18 @@ import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketQuestTransmitRsp; import emu.grasscutter.utils.Position; import java.util.ArrayList; -import java.util.List; -import lombok.val; @Opcodes(PacketOpcodes.QuestTransmitReq) public class HandlerQuestTransmitReq extends PacketHandler { - @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - val req = QuestTransmitReq.parseFrom(payload); - GameMainQuest mainQuest = - session.getPlayer().getQuestManager().getMainQuestById(req.getQuestId() / 100); - List posAndRot = new ArrayList<>(); + var req = QuestTransmitReq.parseFrom(payload); + var mainQuest = session.getPlayer().getQuestManager().getMainQuestById(req.getQuestId() / 100); + + var posAndRot = new ArrayList(); boolean result = false; - if (mainQuest.hasTeleportPostion(req.getQuestId(), posAndRot)) { - int sceneId = + if (mainQuest.hasTeleportPosition(req.getQuestId(), posAndRot)) { + var sceneId = GameData.getTeleportDataMap() .get(req.getQuestId()) .getTransmit_points() @@ -36,6 +32,7 @@ public class HandlerQuestTransmitReq extends PacketHandler { .getWorld() .transferPlayerToScene(session.getPlayer(), sceneId, posAndRot.get(0)); } + session.send(new PacketQuestTransmitRsp(result, req)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneAudioNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneAudioNotify.java index 0bfeddc16..2e6e51915 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneAudioNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneAudioNotify.java @@ -1,8 +1,5 @@ - package emu.grasscutter.server.packet.recv; -import javax.lang.model.type.TypeMirror; - import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; @@ -24,8 +21,9 @@ public class HandlerSceneAudioNotify extends PacketHandler { int type = notify.getType(); List param1 = notify.getParam1List(); - session.getPlayer().getScene().broadcastPacket(new PacketSceneAudioNotify(sourceUid, param2, param3, type, param1)); + session + .getPlayer() + .getScene() + .broadcastPacket(new PacketSceneAudioNotify(sourceUid, param2, param3, type, param1)); } - } - diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java index 6b5cfcf28..b0efc4140 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBornDataReq.java @@ -55,7 +55,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler { // Check if the default Anemo skill should be given. if (!GAME_OPTIONS.questing) { mainCharacter.setSkillDepotData( - GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot)); + GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot)); } // Manually handle adding to team diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockPersonalLineReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockPersonalLineReq.java index f98421cef..7350ecbf5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockPersonalLineReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockPersonalLineReq.java @@ -17,9 +17,7 @@ public class HandlerUnlockPersonalLineReq extends PacketHandler { var req = UnlockPersonalLineReq.parseFrom(payload); var data = GameData.getPersonalLineDataMap().get(req.getPersonalLineId()); if (data == null) { - session.send( - new PacketUnlockPersonalLineRsp( - req.getPersonalLineId(), Retcode.RET_FAIL)); + session.send(new PacketUnlockPersonalLineRsp(req.getPersonalLineId(), Retcode.RET_FAIL)); return; } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropUpdateNotify.java index 11bb0d8ab..5fb1f9ce9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropUpdateNotify.java @@ -5,7 +5,6 @@ import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.AvatarFightPropUpdateNotifyOuterClass.AvatarFightPropUpdateNotify; - import java.util.Map; public class PacketAvatarFightPropUpdateNotify extends BasePacket { diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java index 4a6263b48..fb5b4ca4b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamUpdateNotify.java @@ -14,11 +14,14 @@ public class PacketAvatarTeamUpdateNotify extends BasePacket { var teamManager = player.getTeamManager(); if (teamManager.isUsingTrialTeam()) { - proto.addAllTempAvatarGuidList(teamManager.getActiveTeam().stream() - .map(entity -> entity.getAvatar().getGuid()).toList()); + proto.addAllTempAvatarGuidList( + teamManager.getActiveTeam().stream() + .map(entity -> entity.getAvatar().getGuid()) + .toList()); } else { - teamManager.getTeams().forEach((key, value) -> - proto.putAvatarTeamMap(key, value.toProto(player))); + teamManager + .getTeams() + .forEach((key, value) -> proto.putAvatarTeamMap(key, value.toProto(player))); } this.setData(proto); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBuyResinRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBuyResinRsp.java index 07f8bba01..05a56783b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBuyResinRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBuyResinRsp.java @@ -10,9 +10,10 @@ public class PacketBuyResinRsp extends BasePacket { public PacketBuyResinRsp(Player player, int ret) { super(PacketOpcodes.BuyResinRsp); - this.setData(BuyResinRspOuterClass.BuyResinRsp.newBuilder() - .setCurValue(player.getProperty(PlayerProperty.PROP_PLAYER_RESIN)) - .setRetcode(ret) - .build()); + this.setData( + BuyResinRspOuterClass.BuyResinRsp.newBuilder() + .setCurValue(player.getProperty(PlayerProperty.PROP_PLAYER_RESIN)) + .setRetcode(ret) + .build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeGameTimeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeGameTimeRsp.java index 8c69337cb..fbcee6b76 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeGameTimeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeGameTimeRsp.java @@ -12,9 +12,9 @@ public class PacketChangeGameTimeRsp extends BasePacket { ChangeGameTimeRsp proto = ChangeGameTimeRsp.newBuilder() - .setCurGameTime(player.getWorld().getGameTime()) - .setExtraDays(extraDays) - .build(); + .setCurGameTime(player.getWorld().getGameTime()) + .setExtraDays(extraDays) + .build(); this.setData(proto); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDropHintNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDropHintNotify.java index f72be0df6..6898231e0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDropHintNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDropHintNotify.java @@ -10,9 +10,7 @@ public class PacketDropHintNotify extends BasePacket { public PacketDropHintNotify(int itemId, Vector position) { super(PacketOpcodes.DropHintNotify); - var proto = DropHintNotify.newBuilder() - .addItemIdList(itemId) - .setPosition(position); + var proto = DropHintNotify.newBuilder().addItemIdList(itemId).setPosition(position); this.setData(proto.build()); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java index e5f1a23a6..57a025699 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonEntryInfoRsp.java @@ -5,7 +5,6 @@ import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.DungeonEntryInfoOuterClass.DungeonEntryInfo; import emu.grasscutter.net.proto.DungeonEntryInfoRspOuterClass.DungeonEntryInfoRsp; - import java.util.Arrays; import java.util.List; @@ -36,19 +35,18 @@ public class PacketDungeonEntryInfoRsp extends BasePacket { public PacketDungeonEntryInfoRsp(PointData pointData, List additional) { super(PacketOpcodes.DungeonEntryInfoRsp); - var packet = DungeonEntryInfoRsp.newBuilder() - .setPointId(pointData.getId()); + var packet = DungeonEntryInfoRsp.newBuilder().setPointId(pointData.getId()); // Add dungeon IDs from the point data. if (pointData.getDungeonIds() != null) { Arrays.stream(pointData.getDungeonIds()) - .forEach(id -> packet.addDungeonEntryList( - DungeonEntryInfo.newBuilder().setDungeonId(id))); + .forEach( + id -> packet.addDungeonEntryList(DungeonEntryInfo.newBuilder().setDungeonId(id))); } // Add additional dungeon IDs. - additional.forEach(id -> packet.addDungeonEntryList( - DungeonEntryInfo.newBuilder().setDungeonId(id))); + additional.forEach( + id -> packet.addDungeonEntryList(DungeonEntryInfo.newBuilder().setDungeonId(id))); this.setData(packet); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketResinChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketResinChangeNotify.java index 5f9b8bd92..7d6cb967e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketResinChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketResinChangeNotify.java @@ -8,14 +8,15 @@ import emu.grasscutter.net.proto.ResinChangeNotifyOuterClass.ResinChangeNotify; public class PacketResinChangeNotify extends BasePacket { - public PacketResinChangeNotify(Player player) { + public PacketResinChangeNotify(Player player) { super(PacketOpcodes.ResinChangeNotify); - ResinChangeNotify proto = ResinChangeNotify.newBuilder() - .setCurValue(player.getProperty(PlayerProperty.PROP_PLAYER_RESIN)) - .setNextAddTimestamp(player.getNextResinRefresh()) - .setCurBuyCount(player.getResinBuyCount()) - .build(); + ResinChangeNotify proto = + ResinChangeNotify.newBuilder() + .setCurValue(player.getProperty(PlayerProperty.PROP_PLAYER_RESIN)) + .setNextAddTimestamp(player.getNextResinRefresh()) + .setCurBuyCount(player.getResinBuyCount()) + .build(); this.setData(proto); } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAudioNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAudioNotify.java index 227e2d2b1..8a21848e0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAudioNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAudioNotify.java @@ -7,17 +7,19 @@ import java.util.List; public class PacketSceneAudioNotify extends BasePacket { - public PacketSceneAudioNotify(int sourceUid, List param2, List param3, int type, List param1) { + public PacketSceneAudioNotify( + int sourceUid, List param2, List param3, int type, List param1) { super(PacketOpcodes.SceneAudioNotify); - SceneAudioNotifyOuterClass.SceneAudioNotify proto = SceneAudioNotifyOuterClass.SceneAudioNotify.newBuilder() - .setSourceUid(sourceUid) - .addAllParam2(param2) - .addAllParam3(param3) - .setType(type) - .addAllParam1(param1) - .build(); - + SceneAudioNotifyOuterClass.SceneAudioNotify proto = + SceneAudioNotifyOuterClass.SceneAudioNotify.newBuilder() + .setSourceUid(sourceUid) + .addAllParam2(param2) + .addAllParam3(param3) + .setType(type) + .addAllParam1(param1) + .build(); + this.setData(proto); } -} \ No newline at end of file +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java index b4b604cb9..58dc12f98 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java @@ -10,8 +10,10 @@ public final class PacketServerGlobalValueChangeNotify extends BasePacket { public PacketServerGlobalValueChangeNotify(GameEntity entity, String abilityHash, int value) { super(PacketOpcodes.ServerGlobalValueChangeNotify); - this.setData(ServerGlobalValueChangeNotify.newBuilder() - .setEntityId(entity.getId()).setValue(value) - .setKeyHash(Utils.abilityHash(abilityHash))); + this.setData( + ServerGlobalValueChangeNotify.newBuilder() + .setEntityId(entity.getId()) + .setValue(value) + .setKeyHash(Utils.abilityHash(abilityHash))); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldChestOpenNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldChestOpenNotify.java index 6b9ae3403..dd8ff5ad1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldChestOpenNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldChestOpenNotify.java @@ -5,13 +5,14 @@ import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.WorldChestOpenNotifyOuterClass.WorldChestOpenNotify; public class PacketWorldChestOpenNotify extends BasePacket { - public PacketWorldChestOpenNotify(int groupId,int sceneId,int configId){ + public PacketWorldChestOpenNotify(int groupId, int sceneId, int configId) { super(PacketOpcodes.WorldChestOpenNotify); - this.setData(WorldChestOpenNotify.newBuilder() - .setGroupId(groupId) - .setSceneId(sceneId) - .setConfigId(configId) - .build()); + this.setData( + WorldChestOpenNotify.newBuilder() + .setGroupId(groupId) + .setSceneId(sceneId) + .setConfigId(configId) + .build()); } } diff --git a/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java b/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java index 25e23cb05..30e032987 100644 --- a/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java +++ b/src/main/java/emu/grasscutter/task/tasks/AnnouncementTask.java @@ -56,7 +56,8 @@ public final class AnnouncementTask extends TaskHandler { .toList(); Grasscutter.getGameServer().getAnnouncementSystem().broadcast(toSend); - Grasscutter.getLogger().trace("Broadcast {} announcement(s) to all online players", toSend.size()); + Grasscutter.getLogger() + .trace("Broadcast {} announcement(s) to all online players", toSend.size()); // clear the interval count toSend.forEach(i -> intervalMap.put(i.getTemplateId(), 0)); diff --git a/src/main/java/emu/grasscutter/utils/Crypto.java b/src/main/java/emu/grasscutter/utils/Crypto.java index da25073ad..c63d8f81a 100644 --- a/src/main/java/emu/grasscutter/utils/Crypto.java +++ b/src/main/java/emu/grasscutter/utils/Crypto.java @@ -1,8 +1,8 @@ package emu.grasscutter.utils; +import emu.grasscutter.Grasscutter; import emu.grasscutter.server.http.objects.QueryCurRegionRspJson; import java.io.ByteArrayOutputStream; -import java.io.File; import java.nio.file.Path; import java.security.KeyFactory; import java.security.PrivateKey; @@ -12,11 +12,9 @@ import java.security.Signature; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; -import java.util.Map; import java.util.HashMap; +import java.util.Map; import java.util.regex.Pattern; - -import emu.grasscutter.Grasscutter; import javax.crypto.Cipher; public final class Crypto { @@ -42,8 +40,10 @@ public final class Crypto { ENCRYPT_SEED_BUFFER = FileUtils.readResource("/keys/secretKeyBuffer.bin"); try { - CUR_SIGNING_KEY = KeyFactory.getInstance("RSA") - .generatePrivate(new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der"))); + CUR_SIGNING_KEY = + KeyFactory.getInstance("RSA") + .generatePrivate( + new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der"))); Pattern pattern = Pattern.compile("([0-9]*)_Pub\\.der"); for (Path path : FileUtils.getPathsFromResource("/keys/game_keys")) { @@ -52,8 +52,9 @@ public final class Crypto { var m = pattern.matcher(path.getFileName().toString()); if (m.matches()) { - var key = KeyFactory.getInstance("RSA") - .generatePublic(new X509EncodedKeySpec(FileUtils.read(path))); + var key = + KeyFactory.getInstance("RSA") + .generatePublic(new X509EncodedKeySpec(FileUtils.read(path))); EncryptionKeys.put(Integer.valueOf(m.group(1)), key); } @@ -80,7 +81,8 @@ public final class Crypto { return bytes; } - public static QueryCurRegionRspJson encryptAndSignRegionData(byte[] regionInfo, String key_id) throws Exception { + public static QueryCurRegionRspJson encryptAndSignRegionData(byte[] regionInfo, String key_id) + throws Exception { if (key_id == null) { throw new Exception("Key ID was not set"); } @@ -88,17 +90,18 @@ public final class Crypto { Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, EncryptionKeys.get(Integer.valueOf(key_id))); - //Encrypt regionInfo in chunks + // Encrypt regionInfo in chunks ByteArrayOutputStream encryptedRegionInfoStream = new ByteArrayOutputStream(); - //Thank you so much GH Copilot + // Thank you so much GH Copilot int chunkSize = 256 - 11; int regionInfoLength = regionInfo.length; int numChunks = (int) Math.ceil(regionInfoLength / (double) chunkSize); for (int i = 0; i < numChunks; i++) { - byte[] chunk = Arrays.copyOfRange(regionInfo, i * chunkSize, - Math.min((i + 1) * chunkSize, regionInfoLength)); + byte[] chunk = + Arrays.copyOfRange( + regionInfo, i * chunkSize, Math.min((i + 1) * chunkSize, regionInfoLength)); byte[] encryptedChunk = cipher.doFinal(chunk); encryptedRegionInfoStream.write(encryptedChunk); } diff --git a/src/main/java/emu/grasscutter/utils/Language.java b/src/main/java/emu/grasscutter/utils/Language.java index c93543395..c823a50d3 100644 --- a/src/main/java/emu/grasscutter/utils/Language.java +++ b/src/main/java/emu/grasscutter/utils/Language.java @@ -1,8 +1,8 @@ package emu.grasscutter.utils; import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE; -import static emu.grasscutter.utils.FileUtils.getResourcePath; import static emu.grasscutter.utils.FileUtils.getCachePath; +import static emu.grasscutter.utils.FileUtils.getResourcePath; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -19,7 +19,6 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.io.*; import java.nio.charset.StandardCharsets; -import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; @@ -290,8 +289,10 @@ public final class Language { private static void saveTextMapsCache(Int2ObjectMap input) throws IOException { Files.createDirectories(TEXTMAP_CACHE_PATH.getParent()); - try (var file = new ObjectOutputStream(new BufferedOutputStream( - Files.newOutputStream(TEXTMAP_CACHE_PATH, StandardOpenOption.CREATE), 0x100000))) { + try (var file = + new ObjectOutputStream( + new BufferedOutputStream( + Files.newOutputStream(TEXTMAP_CACHE_PATH, StandardOpenOption.CREATE), 0x100000))) { file.writeInt(TEXTMAP_CACHE_VERSION); file.writeObject(input); }