Refactor Player::GetPos() -> Player::GetPosition()

This commit is contained in:
Melledy 2022-07-19 00:35:54 -07:00
parent 2e19e70fe1
commit cc5b292bc3
13 changed files with 32 additions and 32 deletions

View File

@ -14,7 +14,7 @@ public final class PositionCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> 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())));

View File

@ -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);
}

View File

@ -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);
}

View File

@ -26,7 +26,7 @@ public final class TeleportCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
Position pos = targetPlayer.getPos();
Position pos = targetPlayer.getPosition();
float x = pos.getX();
float y = pos.getY();
float z = pos.getZ();

View File

@ -69,7 +69,7 @@ public class EntityAvatar extends GameEntity {
@Override
public Position getPosition() {
return getPlayer().getPos();
return getPlayer().getPosition();
}
@Override

View File

@ -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;
}
}

View File

@ -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));
}

View File

@ -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();
}

View File

@ -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));

View File

@ -459,7 +459,7 @@ public class Scene {
public synchronized void checkSpawns() {
Set<SpawnDataEntry.GridBlockId> 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<SceneBlock> 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<SceneBlock> 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<SceneGroup> playerMeetGroups(Player player, SceneBlock block){
List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPos().toDoubleArray(),
List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPosition().toDoubleArray(),
Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
List<SceneGroup> 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<SceneNpcBornEntry> loadNpcForPlayer(Player player){
var pos = player.getPos();
var pos = player.getPosition();
var data = GameData.getSceneNpcBornData().get(getId());
if(data == null){
return List.of();

View File

@ -193,7 +193,7 @@ public class World implements Iterable<Player> {
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<Player> {
// 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());

View File

@ -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

View File

@ -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())