Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
80e75fd0
Commit
80e75fd0
authored
Jul 15, 2022
by
KingRainbow44
Browse files
Implement `PlayerMoveEvent`
parent
aa31851e
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/entity/EntityAvatar.java
View file @
80e75fd0
...
@@ -30,6 +30,7 @@ import emu.grasscutter.net.proto.SceneAvatarInfoOuterClass.SceneAvatarInfo;
...
@@ -30,6 +30,7 @@ import emu.grasscutter.net.proto.SceneAvatarInfoOuterClass.SceneAvatarInfo;
import
emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo
;
import
emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo
;
import
emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo
;
import
emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.server.event.player.PlayerMoveEvent
;
import
emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
...
@@ -314,4 +315,21 @@ public class EntityAvatar extends GameEntity {
...
@@ -314,4 +315,21 @@ public class EntityAvatar extends GameEntity {
//
//
return
abilityControlBlock
.
build
();
return
abilityControlBlock
.
build
();
}
}
/**
* Move this entity to a new position.
* Additionally invoke player move event.
* @param newPosition The new position.
* @param rotation The new rotation.
*/
@Override
public
void
move
(
Position
newPosition
,
Position
rotation
)
{
// Invoke player move event.
PlayerMoveEvent
event
=
new
PlayerMoveEvent
(
this
.
getPlayer
(),
PlayerMoveEvent
.
MoveType
.
PLAYER
,
this
.
getPosition
(),
newPosition
);
event
.
call
();
// Set position and rotation.
super
.
move
(
event
.
getDestination
(),
rotation
);
}
}
}
src/main/java/emu/grasscutter/game/entity/GameEntity.java
View file @
80e75fd0
...
@@ -228,6 +228,17 @@ public abstract class GameEntity {
...
@@ -228,6 +228,17 @@ public abstract class GameEntity {
}
}
}
}
/**
* Move this entity to a new position.
* @param position The new position.
* @param rotation The new rotation.
*/
public
void
move
(
Position
position
,
Position
rotation
)
{
// Set the position and rotation.
this
.
getPosition
().
set
(
position
);
this
.
getRotation
().
set
(
rotation
);
}
/**
/**
* Called when this entity is added to the world
* Called when this entity is added to the world
*/
*/
...
...
src/main/java/emu/grasscutter/server/event/player/PlayerMoveEvent.java
0 → 100644
View file @
80e75fd0
package
emu.grasscutter.server.event.player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.Cancellable
;
import
emu.grasscutter.server.event.types.PlayerEvent
;
import
emu.grasscutter.utils.Position
;
/**
* TODO: Allow plugins to change the position of the player.
*/
public
final
class
PlayerMoveEvent
extends
PlayerEvent
implements
Cancellable
{
private
final
MoveType
type
;
private
final
Position
from
;
private
final
Position
to
;
public
PlayerMoveEvent
(
Player
player
,
MoveType
type
,
Position
from
,
Position
to
)
{
super
(
player
);
this
.
type
=
type
;
this
.
from
=
from
;
this
.
to
=
to
;
}
public
MoveType
getMoveType
()
{
return
this
.
type
;
}
public
Position
getSource
()
{
return
this
.
from
;
}
public
Position
getDestination
()
{
return
this
.
to
;
}
public
enum
MoveType
{
/**
* The player has sent a combat invocation to move.
*/
PLAYER
,
/**
* The server has requested that the player moves.
*/
SERVER
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment