From cc5b292bc374edfe11eb7cc54ab06bff30d9da2e Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Tue, 19 Jul 2022 00:35:54 -0700 Subject: [PATCH] Refactor `Player::GetPos()` -> `Player::GetPosition()` --- .../command/commands/PositionCommand.java | 2 +- .../grasscutter/command/commands/SpawnCommand.java | 2 +- .../command/commands/TeleportAllCommand.java | 2 +- .../command/commands/TeleportCommand.java | 2 +- .../emu/grasscutter/game/entity/EntityAvatar.java | 2 +- .../grasscutter/game/managers/MultiplayerSystem.java | 10 +++++----- .../game/managers/mapmark/MapMarksManager.java | 4 ++-- .../java/emu/grasscutter/game/player/Player.java | 12 ++++++------ .../emu/grasscutter/game/player/TeamManager.java | 2 +- src/main/java/emu/grasscutter/game/world/Scene.java | 12 ++++++------ src/main/java/emu/grasscutter/game/world/World.java | 6 +++--- .../java/emu/grasscutter/plugin/api/PlayerHook.java | 4 ++-- .../packet/send/PacketPlayerEnterSceneNotify.java | 4 ++-- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java index 221afe801..0d59fdc54 100644 --- a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java @@ -14,7 +14,7 @@ public final class PositionCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - Position pos = targetPlayer.getPos(); + Position pos = targetPlayer.getPosition(); CommandHandler.sendMessage(sender, translate(sender, "commands.position.success", Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()), Integer.toString(targetPlayer.getSceneId()))); diff --git a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java index 311df8b56..3a962cf28 100644 --- a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java @@ -85,7 +85,7 @@ public final class SpawnCommand implements CommandHandler { double maxRadius = Math.sqrt(amount * 0.2 / Math.PI); for (int i = 0; i < amount; i++) { - Position pos = GetRandomPositionInCircle(targetPlayer.getPos(), maxRadius).addY(3); + Position pos = GetRandomPositionInCircle(targetPlayer.getPosition(), maxRadius).addY(3); if(x != 0 && y != 0 && z != 0) { pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3); } diff --git a/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java index 5a28383a3..5e046a207 100644 --- a/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java @@ -23,7 +23,7 @@ public final class TeleportAllCommand implements CommandHandler { for (Player player : targetPlayer.getWorld().getPlayers()) { if (player.equals(targetPlayer)) continue; - Position pos = targetPlayer.getPos(); + Position pos = targetPlayer.getPosition(); player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos); } diff --git a/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java index 0bc920ac7..21d898af9 100644 --- a/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java @@ -26,7 +26,7 @@ public final class TeleportCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - Position pos = targetPlayer.getPos(); + Position pos = targetPlayer.getPosition(); float x = pos.getX(); float y = pos.getY(); float z = pos.getZ(); diff --git a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java index f200a6559..63d94b866 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java @@ -69,7 +69,7 @@ public class EntityAvatar extends GameEntity { @Override public Position getPosition() { - return getPlayer().getPos(); + return getPlayer().getPosition(); } @Override diff --git a/src/main/java/emu/grasscutter/game/managers/MultiplayerSystem.java b/src/main/java/emu/grasscutter/game/managers/MultiplayerSystem.java index 053121f66..d64a34572 100644 --- a/src/main/java/emu/grasscutter/game/managers/MultiplayerSystem.java +++ b/src/main/java/emu/grasscutter/game/managers/MultiplayerSystem.java @@ -89,11 +89,11 @@ public class MultiplayerSystem extends BaseGameSystem { world.addPlayer(hostPlayer); // Rejoin packet - hostPlayer.sendPacket(new PacketPlayerEnterSceneNotify(hostPlayer, hostPlayer, EnterType.ENTER_TYPE_SELF, EnterReason.HostFromSingleToMp, hostPlayer.getScene().getId(), hostPlayer.getPos())); + hostPlayer.sendPacket(new PacketPlayerEnterSceneNotify(hostPlayer, hostPlayer, EnterType.ENTER_TYPE_SELF, EnterReason.HostFromSingleToMp, hostPlayer.getScene().getId(), hostPlayer.getPosition())); } // Set scene pos and id of requester to the host player's - requester.getPos().set(hostPlayer.getPos()); + requester.getPosition().set(hostPlayer.getPosition()); requester.getRotation().set(hostPlayer.getRotation()); requester.setSceneId(hostPlayer.getSceneId()); @@ -101,7 +101,7 @@ public class MultiplayerSystem extends BaseGameSystem { hostPlayer.getWorld().addPlayer(requester); // Packet - requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, hostPlayer, EnterType.ENTER_TYPE_OTHER, EnterReason.TeamJoin, hostPlayer.getScene().getId(), hostPlayer.getPos())); + requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, hostPlayer, EnterType.ENTER_TYPE_OTHER, EnterReason.TeamJoin, hostPlayer.getScene().getId(), hostPlayer.getPosition())); } public boolean leaveCoop(Player player) { @@ -122,7 +122,7 @@ public class MultiplayerSystem extends BaseGameSystem { world.addPlayer(player); // Packet - player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.ENTER_TYPE_SELF, EnterReason.TeamBack, player.getScene().getId(), player.getPos())); + player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.ENTER_TYPE_SELF, EnterReason.TeamBack, player.getScene().getId(), player.getPosition())); return true; } @@ -149,7 +149,7 @@ public class MultiplayerSystem extends BaseGameSystem { World world = new World(victim); world.addPlayer(victim); - victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.ENTER_TYPE_SELF, EnterReason.TeamKick, victim.getScene().getId(), victim.getPos())); + victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.ENTER_TYPE_SELF, EnterReason.TeamKick, victim.getScene().getId(), victim.getPosition())); return true; } } diff --git a/src/main/java/emu/grasscutter/game/managers/mapmark/MapMarksManager.java b/src/main/java/emu/grasscutter/game/managers/mapmark/MapMarksManager.java index dfde7a0e3..225aa834a 100644 --- a/src/main/java/emu/grasscutter/game/managers/mapmark/MapMarksManager.java +++ b/src/main/java/emu/grasscutter/game/managers/mapmark/MapMarksManager.java @@ -78,9 +78,9 @@ public class MapMarksManager extends BasePlayerManager { y = 300; } Position pos = mapMark.getPosition(); - player.getPos().set(pos.getX(), y, pos.getZ()); + player.getPosition().set(pos.getX(), y, pos.getZ()); if (mapMark.getSceneId() != player.getSceneId()) { - player.getWorld().transferPlayerToScene(player, mapMark.getSceneId(), player.getPos()); + player.getWorld().transferPlayerToScene(player, mapMark.getSceneId(), player.getPosition()); } player.getScene().broadcastPacket(new PacketSceneEntityAppearNotify(player)); } diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index bfc090b93..60a156465 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -97,7 +97,7 @@ public class Player { private String signature; private int headImage; private int nameCardId = 210001; - private Position pos; + private Position position; private Position rotation; private PlayerBirthday birthday; private PlayerCodex codex; @@ -200,7 +200,7 @@ public class Player { this.insectCaptureManager = new InsectCaptureManager(this); this.questManager = new QuestManager(this); - this.pos = new Position(); + this.position = new Position(); this.rotation = new Position(); this.properties = new HashMap<>(); for (PlayerProperty prop : PlayerProperty.values()) { @@ -272,7 +272,7 @@ public class Player { this.setProperty(PlayerProperty.PROP_PLAYER_RESIN, 160, false); this.getFlyCloakList().add(140001); this.getNameCardList().add(210001); - this.getPos().set(GameConstants.START_POSITION); + this.getPosition().set(GameConstants.START_POSITION); this.getRotation().set(0, 307, 0); this.messageHandler = null; this.mapMarksManager = new MapMarksManager(this); @@ -419,8 +419,8 @@ public class Player { this.currentRealmId = currentRealmId; } - public Position getPos() { - return pos; + public Position getPosition() { + return position; } public Position getRotation() { @@ -1182,7 +1182,7 @@ public class Player { public PlayerLocationInfo getPlayerLocationInfo() { return PlayerLocationInfo.newBuilder() .setUid(this.getUid()) - .setPos(this.getPos().toProto()) + .setPos(this.getPosition().toProto()) .setRot(this.getRotation().toProto()) .build(); } diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index cfb1abece..7fe31ab5a 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -662,7 +662,7 @@ public class TeamManager extends BasePlayerDataManager { // Set player position player.setSceneId(3); - player.getPos().set(GameConstants.START_POSITION); + player.getPosition().set(GameConstants.START_POSITION); // Packets getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp)); diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 105e22ff6..85a571293 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -459,7 +459,7 @@ public class Scene { public synchronized void checkSpawns() { Set loadedGridBlocks = new HashSet<>(); for (Player player : this.getPlayers()) { - for (SpawnDataEntry.GridBlockId block : SpawnDataEntry.GridBlockId.getAdjacentGridBlockIds(player.getSceneId(), player.getPos())) + for (SpawnDataEntry.GridBlockId block : SpawnDataEntry.GridBlockId.getAdjacentGridBlockIds(player.getSceneId(), player.getPosition())) loadedGridBlocks.add(block); } if (this.loadedGridBlocks.containsAll(loadedGridBlocks)) { // Don't recalculate static spawns if nothing has changed @@ -555,7 +555,7 @@ public class Scene { public List getPlayerActiveBlocks(Player player){ // consider the borders' entities of blocks, so we check if contains by index return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(), - player.getPos().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange); + player.getPosition().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange); } public void checkBlocks() { Set visible = new HashSet<>(); @@ -582,7 +582,7 @@ public class Scene { }else{ // dynamic load the groups for players in a loaded block var toLoad = this.getPlayers().stream() - .filter(p -> block.contains(p.getPos())) + .filter(p -> block.contains(p.getPosition())) .map(p -> playerMeetGroups(p, block)) .flatMap(Collection::stream) .toList(); @@ -592,7 +592,7 @@ public class Scene { } public List playerMeetGroups(Player player, SceneBlock block){ - List sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPos().toDoubleArray(), + List sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPosition().toDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange); List groups = sceneGroups.stream() @@ -612,7 +612,7 @@ public class Scene { // the groups form here is not added in current scene var groups = players.stream() - .filter(player -> block.contains(player.getPos())) + .filter(player -> block.contains(player.getPosition())) .map(p -> playerMeetGroups(p, block)) .flatMap(Collection::stream) .toList(); @@ -774,7 +774,7 @@ public class Scene { this.npcBornEntrySet.addAll(loadNpcForPlayer(player)); } private List loadNpcForPlayer(Player player){ - var pos = player.getPos(); + var pos = player.getPosition(); var data = GameData.getSceneNpcBornData().get(getId()); if(data == null){ return List.of(); diff --git a/src/main/java/emu/grasscutter/game/world/World.java b/src/main/java/emu/grasscutter/game/world/World.java index 463523191..d4bdbfc83 100644 --- a/src/main/java/emu/grasscutter/game/world/World.java +++ b/src/main/java/emu/grasscutter/game/world/World.java @@ -193,7 +193,7 @@ public class World implements Iterable { World world = new World(victim); world.addPlayer(victim); - victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.ENTER_TYPE_SELF, EnterReason.TeamKick, victim.getSceneId(), victim.getPos())); + victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.ENTER_TYPE_SELF, EnterReason.TeamKick, victim.getSceneId(), victim.getPosition())); } } } @@ -249,10 +249,10 @@ public class World implements Iterable { // Set player position if (pos == null) { - pos = player.getPos(); + pos = player.getPosition(); } - player.getPos().set(pos); + player.getPosition().set(pos); if (oldScene != null) { newScene.setPrevScene(oldScene.getId()); diff --git a/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java b/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java index 0252b860d..5410241a3 100644 --- a/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java +++ b/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java @@ -39,7 +39,7 @@ public final class PlayerHook { * @param sceneId The scene to send the player to. */ public void changeScenes(int sceneId) { - this.player.getWorld().transferPlayerToScene(this.player, sceneId, this.player.getPos()); + this.player.getWorld().transferPlayerToScene(this.player, sceneId, this.player.getPosition()); } /** @@ -81,7 +81,7 @@ public final class PlayerHook { * @param position The position to teleport the player to. */ public void teleport(Position position) { - this.player.getPos().set(position); + this.player.getPosition().set(position); this.player.sendPacket(new PacketPlayerEnterSceneNotify(this.player, EnterType.ENTER_TYPE_JUMP, EnterReason.TransPoint, this.player.getSceneId(), position diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java index 44a4ca006..180fd2e7a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java @@ -21,7 +21,7 @@ public class PacketPlayerEnterSceneNotify extends BasePacket { PlayerEnterSceneNotify proto = PlayerEnterSceneNotify.newBuilder() .setSceneId(player.getSceneId()) - .setPos(player.getPos().toProto()) + .setPos(player.getPosition().toProto()) .setSceneBeginTime(System.currentTimeMillis()) .setType(EnterType.ENTER_TYPE_SELF) .setTargetUid(player.getUid()) @@ -48,7 +48,7 @@ public class PacketPlayerEnterSceneNotify extends BasePacket { PlayerEnterSceneNotify.Builder proto = PlayerEnterSceneNotify.newBuilder() .setPrevSceneId(player.getSceneId()) - .setPrevPos(player.getPos().toProto()) + .setPrevPos(player.getPosition().toProto()) .setSceneId(newScene) .setPos(newPos.toProto()) .setSceneBeginTime(System.currentTimeMillis())