mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 12:12:54 +08:00
Refactor Player::GetPos()
-> Player::GetPosition()
This commit is contained in:
parent
2e19e70fe1
commit
cc5b292bc3
@ -14,7 +14,7 @@ public final class PositionCommand implements CommandHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
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",
|
CommandHandler.sendMessage(sender, translate(sender, "commands.position.success",
|
||||||
Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()),
|
Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()),
|
||||||
Integer.toString(targetPlayer.getSceneId())));
|
Integer.toString(targetPlayer.getSceneId())));
|
||||||
|
@ -85,7 +85,7 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
|
|
||||||
double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
|
double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
|
||||||
for (int i = 0; i < amount; i++) {
|
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) {
|
if(x != 0 && y != 0 && z != 0) {
|
||||||
pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3);
|
pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public final class TeleportAllCommand implements CommandHandler {
|
|||||||
for (Player player : targetPlayer.getWorld().getPlayers()) {
|
for (Player player : targetPlayer.getWorld().getPlayers()) {
|
||||||
if (player.equals(targetPlayer))
|
if (player.equals(targetPlayer))
|
||||||
continue;
|
continue;
|
||||||
Position pos = targetPlayer.getPos();
|
Position pos = targetPlayer.getPosition();
|
||||||
|
|
||||||
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
|
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public final class TeleportCommand implements CommandHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
Position pos = targetPlayer.getPos();
|
Position pos = targetPlayer.getPosition();
|
||||||
float x = pos.getX();
|
float x = pos.getX();
|
||||||
float y = pos.getY();
|
float y = pos.getY();
|
||||||
float z = pos.getZ();
|
float z = pos.getZ();
|
||||||
|
@ -69,7 +69,7 @@ public class EntityAvatar extends GameEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Position getPosition() {
|
public Position getPosition() {
|
||||||
return getPlayer().getPos();
|
return getPlayer().getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,11 +89,11 @@ public class MultiplayerSystem extends BaseGameSystem {
|
|||||||
world.addPlayer(hostPlayer);
|
world.addPlayer(hostPlayer);
|
||||||
|
|
||||||
// Rejoin packet
|
// 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
|
// 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.getRotation().set(hostPlayer.getRotation());
|
||||||
requester.setSceneId(hostPlayer.getSceneId());
|
requester.setSceneId(hostPlayer.getSceneId());
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public class MultiplayerSystem extends BaseGameSystem {
|
|||||||
hostPlayer.getWorld().addPlayer(requester);
|
hostPlayer.getWorld().addPlayer(requester);
|
||||||
|
|
||||||
// Packet
|
// 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) {
|
public boolean leaveCoop(Player player) {
|
||||||
@ -122,7 +122,7 @@ public class MultiplayerSystem extends BaseGameSystem {
|
|||||||
world.addPlayer(player);
|
world.addPlayer(player);
|
||||||
|
|
||||||
// Packet
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ public class MultiplayerSystem extends BaseGameSystem {
|
|||||||
World world = new World(victim);
|
World world = new World(victim);
|
||||||
world.addPlayer(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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,9 @@ public class MapMarksManager extends BasePlayerManager {
|
|||||||
y = 300;
|
y = 300;
|
||||||
}
|
}
|
||||||
Position pos = mapMark.getPosition();
|
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()) {
|
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));
|
player.getScene().broadcastPacket(new PacketSceneEntityAppearNotify(player));
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class Player {
|
|||||||
private String signature;
|
private String signature;
|
||||||
private int headImage;
|
private int headImage;
|
||||||
private int nameCardId = 210001;
|
private int nameCardId = 210001;
|
||||||
private Position pos;
|
private Position position;
|
||||||
private Position rotation;
|
private Position rotation;
|
||||||
private PlayerBirthday birthday;
|
private PlayerBirthday birthday;
|
||||||
private PlayerCodex codex;
|
private PlayerCodex codex;
|
||||||
@ -200,7 +200,7 @@ public class Player {
|
|||||||
this.insectCaptureManager = new InsectCaptureManager(this);
|
this.insectCaptureManager = new InsectCaptureManager(this);
|
||||||
this.questManager = new QuestManager(this);
|
this.questManager = new QuestManager(this);
|
||||||
|
|
||||||
this.pos = new Position();
|
this.position = new Position();
|
||||||
this.rotation = new Position();
|
this.rotation = new Position();
|
||||||
this.properties = new HashMap<>();
|
this.properties = new HashMap<>();
|
||||||
for (PlayerProperty prop : PlayerProperty.values()) {
|
for (PlayerProperty prop : PlayerProperty.values()) {
|
||||||
@ -272,7 +272,7 @@ public class Player {
|
|||||||
this.setProperty(PlayerProperty.PROP_PLAYER_RESIN, 160, false);
|
this.setProperty(PlayerProperty.PROP_PLAYER_RESIN, 160, false);
|
||||||
this.getFlyCloakList().add(140001);
|
this.getFlyCloakList().add(140001);
|
||||||
this.getNameCardList().add(210001);
|
this.getNameCardList().add(210001);
|
||||||
this.getPos().set(GameConstants.START_POSITION);
|
this.getPosition().set(GameConstants.START_POSITION);
|
||||||
this.getRotation().set(0, 307, 0);
|
this.getRotation().set(0, 307, 0);
|
||||||
this.messageHandler = null;
|
this.messageHandler = null;
|
||||||
this.mapMarksManager = new MapMarksManager(this);
|
this.mapMarksManager = new MapMarksManager(this);
|
||||||
@ -419,8 +419,8 @@ public class Player {
|
|||||||
this.currentRealmId = currentRealmId;
|
this.currentRealmId = currentRealmId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position getPos() {
|
public Position getPosition() {
|
||||||
return pos;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position getRotation() {
|
public Position getRotation() {
|
||||||
@ -1182,7 +1182,7 @@ public class Player {
|
|||||||
public PlayerLocationInfo getPlayerLocationInfo() {
|
public PlayerLocationInfo getPlayerLocationInfo() {
|
||||||
return PlayerLocationInfo.newBuilder()
|
return PlayerLocationInfo.newBuilder()
|
||||||
.setUid(this.getUid())
|
.setUid(this.getUid())
|
||||||
.setPos(this.getPos().toProto())
|
.setPos(this.getPosition().toProto())
|
||||||
.setRot(this.getRotation().toProto())
|
.setRot(this.getRotation().toProto())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -662,7 +662,7 @@ public class TeamManager extends BasePlayerDataManager {
|
|||||||
|
|
||||||
// Set player position
|
// Set player position
|
||||||
player.setSceneId(3);
|
player.setSceneId(3);
|
||||||
player.getPos().set(GameConstants.START_POSITION);
|
player.getPosition().set(GameConstants.START_POSITION);
|
||||||
|
|
||||||
// Packets
|
// Packets
|
||||||
getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp));
|
getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp));
|
||||||
|
@ -459,7 +459,7 @@ public class Scene {
|
|||||||
public synchronized void checkSpawns() {
|
public synchronized void checkSpawns() {
|
||||||
Set<SpawnDataEntry.GridBlockId> loadedGridBlocks = new HashSet<>();
|
Set<SpawnDataEntry.GridBlockId> loadedGridBlocks = new HashSet<>();
|
||||||
for (Player player : this.getPlayers()) {
|
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);
|
loadedGridBlocks.add(block);
|
||||||
}
|
}
|
||||||
if (this.loadedGridBlocks.containsAll(loadedGridBlocks)) { // Don't recalculate static spawns if nothing has changed
|
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){
|
public List<SceneBlock> getPlayerActiveBlocks(Player player){
|
||||||
// consider the borders' entities of blocks, so we check if contains by index
|
// consider the borders' entities of blocks, so we check if contains by index
|
||||||
return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(),
|
return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(),
|
||||||
player.getPos().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
|
player.getPosition().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
|
||||||
}
|
}
|
||||||
public void checkBlocks() {
|
public void checkBlocks() {
|
||||||
Set<SceneBlock> visible = new HashSet<>();
|
Set<SceneBlock> visible = new HashSet<>();
|
||||||
@ -582,7 +582,7 @@ public class Scene {
|
|||||||
}else{
|
}else{
|
||||||
// dynamic load the groups for players in a loaded block
|
// dynamic load the groups for players in a loaded block
|
||||||
var toLoad = this.getPlayers().stream()
|
var toLoad = this.getPlayers().stream()
|
||||||
.filter(p -> block.contains(p.getPos()))
|
.filter(p -> block.contains(p.getPosition()))
|
||||||
.map(p -> playerMeetGroups(p, block))
|
.map(p -> playerMeetGroups(p, block))
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.toList();
|
.toList();
|
||||||
@ -592,7 +592,7 @@ public class Scene {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block){
|
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);
|
Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
|
||||||
|
|
||||||
List<SceneGroup> groups = sceneGroups.stream()
|
List<SceneGroup> groups = sceneGroups.stream()
|
||||||
@ -612,7 +612,7 @@ public class Scene {
|
|||||||
|
|
||||||
// the groups form here is not added in current scene
|
// the groups form here is not added in current scene
|
||||||
var groups = players.stream()
|
var groups = players.stream()
|
||||||
.filter(player -> block.contains(player.getPos()))
|
.filter(player -> block.contains(player.getPosition()))
|
||||||
.map(p -> playerMeetGroups(p, block))
|
.map(p -> playerMeetGroups(p, block))
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.toList();
|
.toList();
|
||||||
@ -774,7 +774,7 @@ public class Scene {
|
|||||||
this.npcBornEntrySet.addAll(loadNpcForPlayer(player));
|
this.npcBornEntrySet.addAll(loadNpcForPlayer(player));
|
||||||
}
|
}
|
||||||
private List<SceneNpcBornEntry> loadNpcForPlayer(Player player){
|
private List<SceneNpcBornEntry> loadNpcForPlayer(Player player){
|
||||||
var pos = player.getPos();
|
var pos = player.getPosition();
|
||||||
var data = GameData.getSceneNpcBornData().get(getId());
|
var data = GameData.getSceneNpcBornData().get(getId());
|
||||||
if(data == null){
|
if(data == null){
|
||||||
return List.of();
|
return List.of();
|
||||||
|
@ -193,7 +193,7 @@ public class World implements Iterable<Player> {
|
|||||||
World world = new World(victim);
|
World world = new World(victim);
|
||||||
world.addPlayer(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
|
// Set player position
|
||||||
if (pos == null) {
|
if (pos == null) {
|
||||||
pos = player.getPos();
|
pos = player.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getPos().set(pos);
|
player.getPosition().set(pos);
|
||||||
|
|
||||||
if (oldScene != null) {
|
if (oldScene != null) {
|
||||||
newScene.setPrevScene(oldScene.getId());
|
newScene.setPrevScene(oldScene.getId());
|
||||||
|
@ -39,7 +39,7 @@ public final class PlayerHook {
|
|||||||
* @param sceneId The scene to send the player to.
|
* @param sceneId The scene to send the player to.
|
||||||
*/
|
*/
|
||||||
public void changeScenes(int sceneId) {
|
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.
|
* @param position The position to teleport the player to.
|
||||||
*/
|
*/
|
||||||
public void teleport(Position position) {
|
public void teleport(Position position) {
|
||||||
this.player.getPos().set(position);
|
this.player.getPosition().set(position);
|
||||||
this.player.sendPacket(new PacketPlayerEnterSceneNotify(this.player,
|
this.player.sendPacket(new PacketPlayerEnterSceneNotify(this.player,
|
||||||
EnterType.ENTER_TYPE_JUMP, EnterReason.TransPoint,
|
EnterType.ENTER_TYPE_JUMP, EnterReason.TransPoint,
|
||||||
this.player.getSceneId(), position
|
this.player.getSceneId(), position
|
||||||
|
@ -21,7 +21,7 @@ public class PacketPlayerEnterSceneNotify extends BasePacket {
|
|||||||
|
|
||||||
PlayerEnterSceneNotify proto = PlayerEnterSceneNotify.newBuilder()
|
PlayerEnterSceneNotify proto = PlayerEnterSceneNotify.newBuilder()
|
||||||
.setSceneId(player.getSceneId())
|
.setSceneId(player.getSceneId())
|
||||||
.setPos(player.getPos().toProto())
|
.setPos(player.getPosition().toProto())
|
||||||
.setSceneBeginTime(System.currentTimeMillis())
|
.setSceneBeginTime(System.currentTimeMillis())
|
||||||
.setType(EnterType.ENTER_TYPE_SELF)
|
.setType(EnterType.ENTER_TYPE_SELF)
|
||||||
.setTargetUid(player.getUid())
|
.setTargetUid(player.getUid())
|
||||||
@ -48,7 +48,7 @@ public class PacketPlayerEnterSceneNotify extends BasePacket {
|
|||||||
|
|
||||||
PlayerEnterSceneNotify.Builder proto = PlayerEnterSceneNotify.newBuilder()
|
PlayerEnterSceneNotify.Builder proto = PlayerEnterSceneNotify.newBuilder()
|
||||||
.setPrevSceneId(player.getSceneId())
|
.setPrevSceneId(player.getSceneId())
|
||||||
.setPrevPos(player.getPos().toProto())
|
.setPrevPos(player.getPosition().toProto())
|
||||||
.setSceneId(newScene)
|
.setSceneId(newScene)
|
||||||
.setPos(newPos.toProto())
|
.setPos(newPos.toProto())
|
||||||
.setSceneBeginTime(System.currentTimeMillis())
|
.setSceneBeginTime(System.currentTimeMillis())
|
||||||
|
Loading…
Reference in New Issue
Block a user