diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java index f7b02892b..b196e09a2 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -1,59 +1,43 @@ package emu.grasscutter.command.commands; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.GameDepot; +import emu.grasscutter.data.excels.ItemData; +import emu.grasscutter.data.excels.avatar.AvatarData; +import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; +import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.inventory.ItemType; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.props.FightProperty; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.regex.Pattern; + import static emu.grasscutter.GameConstants.*; import static emu.grasscutter.command.CommandHelpers.*; -import emu.grasscutter.command.*; -import emu.grasscutter.data.*; -import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.data.excels.avatar.AvatarData; -import emu.grasscutter.data.excels.reliquary.*; -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.inventory.*; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.*; -import java.util.*; -import java.util.function.BiConsumer; -import java.util.regex.Pattern; -import lombok.Setter; - -@Command( - label = "give", - aliases = {"g", "item", "giveitem"}, - usage = { - "(||all|weapons|mats|avatars) [lv] [r] [x] [c] [sl]", - " [lv] [x] [] [[,]]..." - }, - permission = "player.give", - permissionTargeted = "player.give.others", - threading = true) +@Command(label = "give", aliases = {"g", "item", "giveitem"}, usage = {"(||all|weapons|mats|avatars) [lv] [r] [x] [c] [sl]", " [lv] [x] [] [[,]]..."}, permission = "player.give", permissionTargeted = "player.give.others", threading = true) public final class GiveCommand implements CommandHandler { - private static final Map> intCommandHandlers = - Map.ofEntries( - Map.entry(lvlRegex, GiveItemParameters::setLvl), - Map.entry(refineRegex, GiveItemParameters::setRefinement), - Map.entry(amountRegex, GiveItemParameters::setAmount), - Map.entry(constellationRegex, GiveItemParameters::setConstellation), - Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel)); + private static final Map> intCommandHandlers = Map.ofEntries(Map.entry(lvlRegex, GiveItemParameters::setLvl), Map.entry(refineRegex, GiveItemParameters::setRefinement), Map.entry(amountRegex, GiveItemParameters::setAmount), Map.entry(constellationRegex, GiveItemParameters::setConstellation), Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel)); private static Avatar makeAvatar(GiveItemParameters param) { - return makeAvatar( - param.avatarData, - param.lvl, - Avatar.getMinPromoteLevel(param.lvl), - param.constellation, - param.skillLevel); + return makeAvatar(param.avatarData, param.lvl, Avatar.getMinPromoteLevel(param.lvl), param.constellation, param.skillLevel); } - private static Avatar makeAvatar( - AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) { + private static Avatar makeAvatar(AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) { Avatar avatar = new Avatar(avatarData); avatar.setLevel(level); avatar.setPromoteLevel(promoteLevel); - avatar - .getSkillDepot() - .getSkillsAndEnergySkill() - .forEach(id -> avatar.setSkillLevel(id, skillLevel)); + avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar.setSkillLevel(id, skillLevel)); avatar.forceConstellationLevel(constellation); avatar.recalcStats(true); avatar.save(); @@ -63,16 +47,13 @@ public final class GiveCommand implements CommandHandler { private static void giveAllAvatars(Player player, GiveItemParameters param) { int promoteLevel = Avatar.getMinPromoteLevel(param.lvl); if (param.constellation < 0 || param.constellation > 6) - param.constellation = - 6; // constellation's default is -1 so if no parameters set for constellations it'll + param.constellation = 6; // constellation's default is -1 so if no parameters set for constellations it'll // automatically be 6 for (AvatarData avatarData : GameData.getAvatarDataMap().values()) { int id = avatarData.getId(); if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars // Don't try to add each avatar to the current team - player.addAvatar( - makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel), - false); + player.addAvatar(makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel), false); } } @@ -112,7 +93,7 @@ public final class GiveCommand implements CommandHandler { item.setTotalExp(totalExp); int numAffixes = param.data.getAppendPropNum() + (param.lvl - 1) / 4; if (param.mainPropId > 0) // Keep random mainProp if we didn't specify one - item.setMainPropId(param.mainPropId); + item.setMainPropId(param.mainPropId); if (param.appendPropIdList != null) { item.getAppendPropIdList().clear(); item.getAppendPropIdList().addAll(param.appendPropIdList); @@ -124,17 +105,14 @@ public final class GiveCommand implements CommandHandler { return items; } - private static int getArtifactMainProp(ItemData itemData, FightProperty prop) - throws IllegalArgumentException { + private static int getArtifactMainProp(ItemData itemData, FightProperty prop) throws IllegalArgumentException { if (prop != FightProperty.FIGHT_PROP_NONE) - for (ReliquaryMainPropData data : - GameDepot.getRelicMainPropList(itemData.getMainPropDepotId())) + for (ReliquaryMainPropData data : GameDepot.getRelicMainPropList(itemData.getMainPropDepotId())) if (data.getWeight() > 0 && data.getFightProp() == prop) return data.getId(); throw new IllegalArgumentException(); } - private static List getArtifactAffixes(ItemData itemData, FightProperty prop) - throws IllegalArgumentException { + private static List getArtifactAffixes(ItemData itemData, FightProperty prop) throws IllegalArgumentException { if (prop == FightProperty.FIGHT_PROP_NONE) { throw new IllegalArgumentException(); } @@ -147,8 +125,7 @@ public final class GiveCommand implements CommandHandler { return affixes; } - private static int getAppendPropId(String substatText, ItemData itemData) - throws IllegalArgumentException { + private static int getAppendPropId(String substatText, ItemData itemData) throws IllegalArgumentException { // If the given substat text is an integer, we just use that as the append prop ID. try { return Integer.parseInt(substatText); @@ -165,8 +142,7 @@ public final class GiveCommand implements CommandHandler { substatTier = Integer.parseInt(substatArgs[1]); } - List substats = - getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType)); + List substats = getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType)); if (substats.isEmpty()) { throw new IllegalArgumentException(); @@ -178,8 +154,7 @@ public final class GiveCommand implements CommandHandler { } } - private static void parseRelicArgs(GiveItemParameters param, List args) - throws IllegalArgumentException { + private static void parseRelicArgs(GiveItemParameters param, List args) throws IllegalArgumentException { // Get the main stat from the arguments. // If the given argument is an integer, we use that. // If not, we check if the argument string is in the main prop map. @@ -189,8 +164,7 @@ public final class GiveCommand implements CommandHandler { param.mainPropId = Integer.parseInt(mainPropIdString); } catch (NumberFormatException ignored) { // This can in turn throw an exception which we don't want to catch here. - param.mainPropId = - getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString)); + param.mainPropId = getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString)); } // Get substats. @@ -271,8 +245,7 @@ public final class GiveCommand implements CommandHandler { giveAllWeapons(player, param); } - private GiveItemParameters parseArgs(Player sender, List args) - throws IllegalArgumentException { + private GiveItemParameters parseArgs(Player sender, List args) throws IllegalArgumentException { GiveItemParameters param = new GiveItemParameters(); // Extract any tagged arguments (e.g. "lv90", "x100", "r5") @@ -314,9 +287,7 @@ public final class GiveCommand implements CommandHandler { param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000); isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY)); - if (!isRelic - && !args.isEmpty() - && (param.amount == 1)) { // A concession for the people that truly hate [x]. + if (!isRelic && !args.isEmpty() && (param.amount == 1)) { // A concession for the people that truly hate [x]. try { param.amount = Integer.parseInt(args.remove(0)); } catch (NumberFormatException e) { @@ -394,8 +365,7 @@ public final class GiveCommand implements CommandHandler { if (param.avatarData != null) { Avatar avatar = makeAvatar(param); targetPlayer.addAvatar(avatar); - CommandHandler.sendTranslatedMessage( - sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid()); + CommandHandler.sendTranslatedMessage(sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid()); return; } // If it's not an avatar, it needs to be a valid item @@ -406,54 +376,37 @@ public final class GiveCommand implements CommandHandler { switch (param.data.getItemType()) { case ITEM_WEAPON: - targetPlayer - .getInventory() - .addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop); - CommandHandler.sendTranslatedMessage( - sender, - "commands.give.given_with_level_and_refinement", - param.id, - param.lvl, - param.refinement, - param.amount, - targetPlayer.getUid()); + targetPlayer.getInventory().addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop); + CommandHandler.sendTranslatedMessage(sender, "commands.give.given_with_level_and_refinement", param.id, param.lvl, param.refinement, param.amount, targetPlayer.getUid()); return; case ITEM_RELIQUARY: targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop); - CommandHandler.sendTranslatedMessage( - sender, - "commands.give.given_level", - param.id, - param.lvl, - param.amount, - targetPlayer.getUid()); + CommandHandler.sendTranslatedMessage(sender, "commands.give.given_level", param.id, param.lvl, param.amount, targetPlayer.getUid()); return; default: - targetPlayer - .getInventory() - .addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop); - CommandHandler.sendTranslatedMessage( - sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid()); + targetPlayer.getInventory().addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop); + CommandHandler.sendTranslatedMessage(sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid()); } } catch (IllegalArgumentException ignored) { } } private enum GiveAllType { - NONE, - ALL, - WEAPONS, - MATS, - AVATARS + NONE, ALL, WEAPONS, MATS, AVATARS } private static class GiveItemParameters { public int id; - @Setter public int lvl = 0; - @Setter public int amount = 1; - @Setter public int refinement = 1; - @Setter public int constellation = -1; - @Setter public int skillLevel = 1; + @Setter + public int lvl = 0; + @Setter + public int amount = 1; + @Setter + public int refinement = 1; + @Setter + public int constellation = -1; + @Setter + public int skillLevel = 1; public int mainPropId = -1; public List appendPropIdList; public ItemData data; diff --git a/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java b/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java index 0f1b1453f..793bfdcab 100644 --- a/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java +++ b/src/main/java/emu/grasscutter/game/managers/cooking/CookingCompoundManager.java @@ -4,7 +4,8 @@ import emu.grasscutter.data.GameData; import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.CompoundData; import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.*; +import emu.grasscutter.game.player.BasePlayerManager; +import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; import emu.grasscutter.net.proto.GetCompoundDataReqOuterClass.GetCompoundDataReq; @@ -12,8 +13,12 @@ import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; import emu.grasscutter.net.proto.PlayerCompoundMaterialReqOuterClass.PlayerCompoundMaterialReq; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.TakeCompoundOutputReqOuterClass.TakeCompoundOutputReq; -import emu.grasscutter.server.packet.send.*; +import emu.grasscutter.server.packet.send.PackageTakeCompoundOutputRsp; +import emu.grasscutter.server.packet.send.PacketCompoundDataNotify; +import emu.grasscutter.server.packet.send.PacketGetCompoundDataRsp; +import emu.grasscutter.server.packet.send.PacketPlayerCompoundMaterialRsp; import emu.grasscutter.utils.Utils; + import java.util.*; public class CookingCompoundManager extends BasePlayerManager { @@ -29,33 +34,24 @@ public class CookingCompoundManager extends BasePlayerManager { public static void initialize() { defaultUnlockedCompounds = new HashSet<>(); compoundGroups = new HashMap<>(); - GameData.getCompoundDataMap() - .forEach( - (id, compound) -> { - if (compound.isDefaultUnlocked()) { - defaultUnlockedCompounds.add(id); - } - compoundGroups.computeIfAbsent(compound.getGroupId(), gid -> new HashSet<>()).add(id); - }); + GameData.getCompoundDataMap().forEach((id, compound) -> { + if (compound.isDefaultUnlocked()) { + defaultUnlockedCompounds.add(id); + } + compoundGroups.computeIfAbsent(compound.getGroupId(), gid -> new HashSet<>()).add(id); + }); // TODO:Because we haven't implemented fishing feature,unlock all compounds related to // fish.Besides,it should be bound to player rather than manager. unlocked = new HashSet<>(defaultUnlockedCompounds); if (compoundGroups.containsKey(3)) // Avoid NPE from Resources error - unlocked.addAll(compoundGroups.get(3)); + unlocked.addAll(compoundGroups.get(3)); } private synchronized List getCompoundQueueData() { - List compoundQueueData = - new ArrayList<>(player.getActiveCookCompounds().size()); + List compoundQueueData = new ArrayList<>(player.getActiveCookCompounds().size()); int currentTime = Utils.getCurrentSeconds(); for (var item : player.getActiveCookCompounds().values()) { - var data = - CompoundQueueData.newBuilder() - .setCompoundId(item.getCompoundId()) - .setOutputCount(item.getOutputCount(currentTime)) - .setOutputTime(item.getOutputTime(currentTime)) - .setWaitCount(item.getWaitCount(currentTime)) - .build(); + var data = CompoundQueueData.newBuilder().setCompoundId(item.getCompoundId()).setOutputCount(item.getOutputCount(currentTime)).setOutputTime(item.getOutputTime(currentTime)).setWaitCount(item.getWaitCount(currentTime)).build(); compoundQueueData.add(data); } return compoundQueueData; @@ -77,16 +73,14 @@ public class CookingCompoundManager extends BasePlayerManager { return; } // check whether the queue is full - if (activeCompounds.containsKey(id) - && activeCompounds.get(id).getTotalCount() + count > compound.getQueueSize()) { + if (activeCompounds.containsKey(id) && activeCompounds.get(id).getTotalCount() + count > compound.getQueueSize()) { player.sendPacket(new PacketPlayerCompoundMaterialRsp(Retcode.RET_COMPOUND_QUEUE_FULL_VALUE)); return; } // try to consume raw materials if (!player.getInventory().payItems(compound.getInputVec(), count)) { // TODO:I'm not sure whether retcode is correct. - player.sendPacket( - new PacketPlayerCompoundMaterialRsp(Retcode.RET_ITEM_COUNT_NOT_ENOUGH_VALUE)); + player.sendPacket(new PacketPlayerCompoundMaterialRsp(Retcode.RET_ITEM_COUNT_NOT_ENOUGH_VALUE)); return; } ActiveCookCompoundData c; @@ -98,13 +92,7 @@ public class CookingCompoundManager extends BasePlayerManager { c = new ActiveCookCompoundData(id, compound.getCostTime(), count, currentTime); activeCompounds.put(id, c); } - var data = - CompoundQueueData.newBuilder() - .setCompoundId(id) - .setOutputCount(c.getOutputCount(currentTime)) - .setOutputTime(c.getOutputTime(currentTime)) - .setWaitCount(c.getWaitCount(currentTime)) - .build(); + var data = CompoundQueueData.newBuilder().setCompoundId(id).setOutputCount(c.getOutputCount(currentTime)).setOutputTime(c.getOutputTime(currentTime)).setWaitCount(c.getWaitCount(currentTime)).build(); player.sendPacket(new PacketPlayerCompoundMaterialRsp(data)); } @@ -136,20 +124,9 @@ public class CookingCompoundManager extends BasePlayerManager { // give player the rewards if (success) { player.getInventory().addItems(allRewards.values(), ActionReason.Compound); - player.sendPacket( - new PackageTakeCompoundOutputRsp( - allRewards.values().stream() - .map( - i -> - ItemParam.newBuilder() - .setItemId(i.getItemId()) - .setCount(i.getCount()) - .build()) - .toList(), - Retcode.RET_SUCC_VALUE)); + player.sendPacket(new PackageTakeCompoundOutputRsp(allRewards.values().stream().map(i -> ItemParam.newBuilder().setItemId(i.getItemId()).setCount(i.getCount()).build()).toList(), Retcode.RET_SUCC_VALUE)); } else { - player.sendPacket( - new PackageTakeCompoundOutputRsp(null, Retcode.RET_COMPOUND_NOT_FINISH_VALUE)); + player.sendPacket(new PackageTakeCompoundOutputRsp(null, Retcode.RET_COMPOUND_NOT_FINISH_VALUE)); } } diff --git a/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java b/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java index a57dc5830..949747717 100644 --- a/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java +++ b/src/main/java/emu/grasscutter/game/world/SceneGroupInstance.java @@ -1,31 +1,51 @@ package emu.grasscutter.game.world; -import dev.morphia.annotations.*; +import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Id; +import dev.morphia.annotations.Indexed; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.player.Player; -import emu.grasscutter.scripts.data.*; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import lombok.*; +import emu.grasscutter.scripts.data.SceneGadget; +import emu.grasscutter.scripts.data.SceneGroup; +import lombok.Getter; +import lombok.Setter; import org.bson.types.ObjectId; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + @Entity(value = "group_instances", useDiscriminator = false) public final class SceneGroupInstance { - @Id private ObjectId id; + @Id + private ObjectId id; - @Indexed private int ownerUid; // This group is owned by the host player - @Getter private int groupId; + @Indexed + private int ownerUid; // This group is owned by the host player + @Getter + private int groupId; - @Getter private transient SceneGroup luaGroup; - @Getter @Setter private int targetSuiteId; - @Getter @Setter private int activeSuiteId; - @Getter private final Set deadEntities; // Config_ids + @Getter + private transient SceneGroup luaGroup; + @Getter + @Setter + private int targetSuiteId; + @Getter + @Setter + private int activeSuiteId; + @Getter + private final Set deadEntities; // Config_ids private boolean isCached; - @Getter private final Map cachedGadgetStates; - @Getter private final Map cachedVariables; + @Getter + private final Map cachedGadgetStates; + @Getter + private final Map cachedVariables; - @Getter @Setter private int lastTimeRefreshed; + @Getter + @Setter + private int lastTimeRefreshed; public SceneGroupInstance(SceneGroup group, Player owner) { this.luaGroup = group; @@ -39,10 +59,11 @@ public final class SceneGroupInstance { this.cachedVariables = new ConcurrentHashMap<>(); this.isCached = - false; // This is true when the group is not loaded on scene but caches suite data + false; // This is true when the group is not loaded on scene but caches suite data } - @Deprecated // Morphia only! + @Deprecated + // Morphia only! SceneGroupInstance() { this.cachedVariables = new ConcurrentHashMap<>(); this.deadEntities = new HashSet<>(); @@ -65,7 +86,7 @@ public final class SceneGroupInstance { public void cacheGadgetState(SceneGadget g, int state) { if (g.persistent) // Only cache when is persistent - cachedGadgetStates.put(g.config_id, state); + cachedGadgetStates.put(g.config_id, state); } public int getCachedGadgetState(SceneGadget g) { diff --git a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java index 0cdeb63cd..d1e47b54d 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java +++ b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java @@ -1,13 +1,17 @@ package emu.grasscutter.server.game; -import static emu.grasscutter.config.Configuration.GAME_INFO; - import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerDebugMode; -import emu.grasscutter.net.packet.*; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.packet.PacketOpcodesUtils; import emu.grasscutter.server.event.game.ReceivePacketEvent; import emu.grasscutter.server.game.GameSession.SessionState; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +import static emu.grasscutter.config.Configuration.GAME_INFO; public final class GameServerPacketHandler { private final Int2ObjectMap handlers; @@ -29,7 +33,7 @@ public final class GameServerPacketHandler { this.handlers.put(opcode.value(), packetHandler); } catch (Exception e) { Grasscutter.getLogger() - .warn("Unable to register handler {}.", handlerClass.getSimpleName(), e); + .warn("Unable to register handler {}.", handlerClass.getSimpleName(), e); } } @@ -79,7 +83,7 @@ public final class GameServerPacketHandler { ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload); event.call(); if (!event.isCanceled()) // If event is not canceled, continue. - handler.handle(session, header, event.getPacketData()); + handler.handle(session, header, event.getPacketData()); } catch (Exception ex) { // TODO Remove this when no more needed ex.printStackTrace(); @@ -89,7 +93,7 @@ public final class GameServerPacketHandler { // Log unhandled packets if (GAME_INFO.logPackets == ServerDebugMode.MISSING - || GAME_INFO.logPackets == ServerDebugMode.ALL) { + || GAME_INFO.logPackets == ServerDebugMode.ALL) { Grasscutter.getLogger() .info("Unhandled packet ({}): {}", opcode, PacketOpcodesUtils.getOpcodeName(opcode)); } diff --git a/src/main/java/emu/grasscutter/utils/JsonAdapters.java b/src/main/java/emu/grasscutter/utils/JsonAdapters.java index a44e46bac..d5f765bee 100644 --- a/src/main/java/emu/grasscutter/utils/JsonAdapters.java +++ b/src/main/java/emu/grasscutter/utils/JsonAdapters.java @@ -1,16 +1,25 @@ package emu.grasscutter.utils; -import com.google.gson.*; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.*; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; import emu.grasscutter.data.common.DynamicFloat; -import emu.grasscutter.game.world.*; +import emu.grasscutter.game.world.GridPosition; +import emu.grasscutter.game.world.Position; import it.unimi.dsi.fastutil.floats.FloatArrayList; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; +import lombok.val; + import java.io.IOException; import java.lang.reflect.Field; -import java.util.*; -import lombok.val; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Objects; public interface JsonAdapters { class DynamicFloatAdapter extends TypeAdapter { @@ -31,24 +40,25 @@ public interface JsonAdapters { val opStack = new ArrayList(); while (reader.hasNext()) { opStack.add( - switch (reader.peek()) { - case STRING -> new DynamicFloat.StackOp(reader.nextString()); - case NUMBER -> new DynamicFloat.StackOp((float) reader.nextDouble()); - case BOOLEAN -> new DynamicFloat.StackOp(reader.nextBoolean()); - default -> throw new IOException( - "Invalid DynamicFloat definition - " + reader.peek().name()); - }); + switch (reader.peek()) { + case STRING -> new DynamicFloat.StackOp(reader.nextString()); + case NUMBER -> new DynamicFloat.StackOp((float) reader.nextDouble()); + case BOOLEAN -> new DynamicFloat.StackOp(reader.nextBoolean()); + default -> throw new IOException( + "Invalid DynamicFloat definition - " + reader.peek().name()); + }); } reader.endArray(); return new DynamicFloat(opStack); } default -> throw new IOException( - "Invalid DynamicFloat definition - " + reader.peek().name()); + "Invalid DynamicFloat definition - " + reader.peek().name()); } } @Override - public void write(JsonWriter writer, DynamicFloat f) {} + public void write(JsonWriter writer, DynamicFloat f) { + } } class IntListAdapter extends TypeAdapter { @@ -70,7 +80,7 @@ public interface JsonAdapters { public void write(JsonWriter writer, IntList l) throws IOException { writer.beginArray(); for (val i : l) // .forEach() doesn't appreciate exceptions - writer.value(i); + writer.value(i); writer.endArray(); } } @@ -107,7 +117,7 @@ public interface JsonAdapters { throw new IOException("Invalid GridPosition definition - " + in.peek().name()); return new GridPosition( - Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); + Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); } }