Format code [skip actions]

This commit is contained in:
github-actions 2023-11-10 02:57:50 +00:00
parent f1c1a84683
commit 13c40b53a7
8 changed files with 124 additions and 134 deletions

View File

@ -13,17 +13,16 @@ import emu.grasscutter.net.proto.HomeAvatarTalkFinishInfoOuterClass.HomeAvatarTa
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntSets; import it.unimi.dsi.fastutil.ints.IntSets;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
@Entity(value = "homes", useDiscriminator = false) @Entity(value = "homes", useDiscriminator = false)
@Data @Data
@ -39,8 +38,9 @@ public class GameHome {
.map(SceneData::getId) .map(SceneData::getId)
.collect(Collectors.toUnmodifiableSet()); .collect(Collectors.toUnmodifiableSet());
public static final Set<Integer> HOME_MODULE_IDS = public static final Set<Integer> HOME_MODULE_IDS =
GameData.getHomeWorldModuleDataMap().isEmpty() ? GameData.getHomeWorldModuleDataMap().isEmpty()
IntSets.fromTo(1, 6) : GameData.getHomeWorldModuleDataMap().keySet(); ? IntSets.fromTo(1, 6)
: GameData.getHomeWorldModuleDataMap().keySet();
@Id String id; @Id String id;
@ -205,7 +205,9 @@ public class GameHome {
return; return;
} }
this.player.getRealmList().removeIf(integer -> !HOME_MODULE_IDS.contains(integer)); // Delete invalid module ids. this.player
.getRealmList()
.removeIf(integer -> !HOME_MODULE_IDS.contains(integer)); // Delete invalid module ids.
if (this.player.getRealmList().isEmpty()) { if (this.player.getRealmList().isEmpty()) {
this.player.setRealmList(null); this.player.setRealmList(null);
@ -217,7 +219,11 @@ public class GameHome {
int firstRId = this.player.getRealmList().iterator().next(); int firstRId = this.player.getRealmList().iterator().next();
this.player.setCurrentRealmId(firstRId); this.player.setCurrentRealmId(firstRId);
this.player.save(); this.player.save();
Grasscutter.getLogger().info("Set player {}'s current realm id to {} cuz the id is invalid.", this.player.getUid(), firstRId); Grasscutter.getLogger()
.info(
"Set player {}'s current realm id to {} cuz the id is invalid.",
this.player.getUid(),
firstRId);
} }
this.player.getCurHomeWorld().refreshModuleManager(); // Apply module id fix. this.player.getCurHomeWorld().refreshModuleManager(); // Apply module id fix.
@ -268,8 +274,7 @@ public class GameHome {
return this.finishedTalkIdMap.get(avatarId); return this.finishedTalkIdMap.get(avatarId);
} }
public List<HomeAvatarTalkFinishInfo> public List<HomeAvatarTalkFinishInfo> toAvatarTalkFinishInfoProto() {
toAvatarTalkFinishInfoProto() {
if (this.finishedTalkIdMap == null) { if (this.finishedTalkIdMap == null) {
this.finishedTalkIdMap = new HashMap<>(); this.finishedTalkIdMap = new HashMap<>();
} }

View File

@ -12,14 +12,13 @@ import emu.grasscutter.net.proto.HomeAvatarSummonAllEventNotifyOuterClass.HomeAv
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import emu.grasscutter.server.packet.send.PacketHomeAvatarSummonAllEventNotify; import emu.grasscutter.server.packet.send.PacketHomeAvatarSummonAllEventNotify;
import emu.grasscutter.utils.Either; import emu.grasscutter.utils.Either;
import java.util.*;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Stream;
@Getter @Getter
@FieldDefaults(level = AccessLevel.PRIVATE) @FieldDefaults(level = AccessLevel.PRIVATE)
public class HomeModuleManager { public class HomeModuleManager {
@ -27,10 +26,8 @@ public class HomeModuleManager {
final HomeWorld homeWorld; final HomeWorld homeWorld;
final GameHome home; final GameHome home;
final int moduleId; final int moduleId;
@Nullable @Nullable final HomeScene outdoor;
final HomeScene outdoor; @Nullable HomeScene indoor;
@Nullable
HomeScene indoor;
final List<HomeAvatarRewardEvent> rewardEvents; final List<HomeAvatarRewardEvent> rewardEvents;
final List<HomeAvatarSummonEvent> summonEvents; final List<HomeAvatarSummonEvent> summonEvents;
@ -159,8 +156,8 @@ public class HomeModuleManager {
Player owner, int avatarId, int guid, int suiteId) { Player owner, int avatarId, int guid, int suiteId) {
HomeSuiteItem targetSuite = null; HomeSuiteItem targetSuite = null;
if (owner.getScene() instanceof HomeScene homeScene) { if (owner.getScene() instanceof HomeScene homeScene) {
targetSuite = homeScene targetSuite =
.getSceneItem().getBlockItems().values().stream() homeScene.getSceneItem().getBlockItems().values().stream()
.map(HomeBlockItem::getSuiteList) .map(HomeBlockItem::getSuiteList)
.flatMap(Collection::stream) .flatMap(Collection::stream)
.filter(suite -> suite.getGuid() == guid) .filter(suite -> suite.getGuid() == guid)
@ -224,13 +221,11 @@ public class HomeModuleManager {
return this.rewardEvents.stream().anyMatch(e -> e.getAvatarId() == avatarId); return this.rewardEvents.stream().anyMatch(e -> e.getAvatarId() == avatarId);
} }
@Nullable @Nullable public HomeSceneItem getOutdoorSceneItem() {
public HomeSceneItem getOutdoorSceneItem() {
return this.outdoor == null ? null : this.outdoor.getSceneItem(); return this.outdoor == null ? null : this.outdoor.getSceneItem();
} }
@Nullable @Nullable public HomeSceneItem getIndoorSceneItem() {
public HomeSceneItem getIndoorSceneItem() {
return this.indoor == null ? null : this.indoor.getSceneItem(); return this.indoor == null ? null : this.indoor.getSceneItem();
} }

View File

@ -10,11 +10,10 @@ import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify; import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify; import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify; import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify;
import lombok.Getter;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.annotation.Nullable;
import lombok.Getter;
@Getter @Getter
public class HomeWorld extends World { public class HomeWorld extends World {
@ -170,8 +169,7 @@ public class HomeWorld extends World {
} }
@Override @Override
@Nullable @Nullable public HomeScene getSceneById(int sceneId) {
public HomeScene getSceneById(int sceneId) {
var scene = this.getScenes().get(sceneId); var scene = this.getScenes().get(sceneId);
if (scene instanceof HomeScene homeScene) { if (scene instanceof HomeScene homeScene) {
return homeScene; return homeScene;

View File

@ -144,10 +144,7 @@ public class HomeWorldMPSystem extends BaseGameSystem {
Position pos; Position pos;
if (scene != null) { if (scene != null) {
pos = pos = toSafe ? scene.getScriptManager().getConfig().born_pos : item.getBornPos();
toSafe
? scene.getScriptManager().getConfig().born_pos
: item.getBornPos();
} else { } else {
pos = item.getBornPos(); pos = item.getBornPos();
} }

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.world; package emu.grasscutter.game.world;
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.dungeon.DungeonData; import emu.grasscutter.data.excels.dungeon.DungeonData;
@ -27,11 +29,6 @@ import io.netty.util.concurrent.FastThreadLocalThread;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -40,8 +37,10 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT; import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;
public class World implements Iterable<Player> { public class World implements Iterable<Player> {
@Getter private final GameServer server; @Getter private final GameServer server;
@ -140,8 +139,7 @@ public class World implements Iterable<Player> {
* @param sceneId The scene ID. * @param sceneId The scene ID.
* @return The scene. * @return The scene.
*/ */
@Nullable @Nullable public Scene getSceneById(int sceneId) {
public Scene getSceneById(int sceneId) {
// Get scene normally // Get scene normally
var scene = this.getScenes().get(sceneId); var scene = this.getScenes().get(sceneId);
if (scene != null) { if (scene != null) {

View File

@ -34,8 +34,7 @@ public class HandlerHomeSceneJumpReq extends PacketHandler {
pos = home.getSceneMap().get(realmId).getBornPos(); pos = home.getSceneMap().get(realmId).getBornPos();
} }
world.transferPlayerToScene( world.transferPlayerToScene(session.getPlayer(), scene.getId(), pos);
session.getPlayer(), scene.getId(), pos);
session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene())); session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene()));
} }

View File

@ -10,10 +10,8 @@ public class PacketHomeChangeModuleRsp extends BasePacket {
public PacketHomeChangeModuleRsp(int targetModuleId) { public PacketHomeChangeModuleRsp(int targetModuleId) {
super(PacketOpcodes.HomeChangeModuleRsp); super(PacketOpcodes.HomeChangeModuleRsp);
var proto = HomeChangeModuleRsp.newBuilder() var proto =
.setRetcode(0) HomeChangeModuleRsp.newBuilder().setRetcode(0).setTargetModuleId(targetModuleId).build();
.setTargetModuleId(targetModuleId)
.build();
this.setData(proto); this.setData(proto);
} }
@ -21,7 +19,6 @@ public class PacketHomeChangeModuleRsp extends BasePacket {
public PacketHomeChangeModuleRsp(Retcode retcode) { public PacketHomeChangeModuleRsp(Retcode retcode) {
super(PacketOpcodes.HomeChangeModuleRsp); super(PacketOpcodes.HomeChangeModuleRsp);
this.setData(HomeChangeModuleRsp.newBuilder() this.setData(HomeChangeModuleRsp.newBuilder().setRetcode(retcode.getNumber()));
.setRetcode(retcode.getNumber()));
} }
} }

View File

@ -8,7 +8,6 @@ import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass.HomeMarkPointNotify; import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass.HomeMarkPointNotify;
import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData; import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
@ -30,7 +29,9 @@ public class PacketHomeMarkPointNotify extends BasePacket {
var moduleId = owner.getCurrentRealmId(); var moduleId = owner.getCurrentRealmId();
var scene = world.getSceneById(moduleId + 2000); var scene = world.getSceneById(moduleId + 2000);
if (scene == null) { if (scene == null) {
Grasscutter.getLogger().warn("Current Realm id is invalid! SceneExcelConfigData.json, game resource not loaded correctly or the realm id maybe wrong?!"); Grasscutter.getLogger()
.warn(
"Current Realm id is invalid! SceneExcelConfigData.json, game resource not loaded correctly or the realm id maybe wrong?!");
return; return;
} }
var homeScene = home.getHomeSceneItem(moduleId + 2000); var homeScene = home.getHomeSceneItem(moduleId + 2000);