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
f6b4016f
Commit
f6b4016f
authored
Jul 15, 2022
by
KingRainbow44
Browse files
Add `PlayerTeleportEvent`
parent
02ca5cf2
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java
View file @
f6b4016f
...
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.utils.Position
;
import
java.util.List
;
...
...
@@ -19,15 +20,20 @@ public final class TeleportAllCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleportAll.error"
));
return
;
}
for
(
Player
player
:
targetPlayer
.
getWorld
().
getPlayers
())
{
if
(
player
.
equals
(
targetPlayer
))
continue
;
Position
pos
=
targetPlayer
.
getPos
();
PlayerTeleportEvent
event
=
new
PlayerTeleportEvent
(
targetPlayer
,
PlayerTeleportEvent
.
TeleportType
.
COMMAND
,
targetPlayer
.
getPos
(),
pos
);
event
.
call
();
player
.
getWorld
().
transferPlayerToScene
(
player
,
targetPlayer
.
getSceneId
(),
pos
);
if
(!
event
.
isCanceled
())
player
.
getWorld
().
transferPlayerToScene
(
player
,
targetPlayer
.
getSceneId
(),
event
.
getDestination
());
}
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleportAll.success"
));
}
}
src/main/java/emu/grasscutter/command/commands/TeleportCommand.java
View file @
f6b4016f
...
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.utils.Position
;
import
java.util.List
;
...
...
@@ -54,12 +55,16 @@ public final class TeleportCommand implements CommandHandler {
}
Position
target_pos
=
new
Position
(
x
,
y
,
z
);
boolean
result
=
targetPlayer
.
getWorld
().
transferPlayerToScene
(
targetPlayer
,
sceneId
,
target_pos
);
PlayerTeleportEvent
event
=
new
PlayerTeleportEvent
(
targetPlayer
,
PlayerTeleportEvent
.
TeleportType
.
COMMAND
,
targetPlayer
.
getPos
(),
target_pos
);
event
.
call
();
boolean
result
=
!
event
.
isCanceled
()
||
targetPlayer
.
getWorld
().
transferPlayerToScene
(
targetPlayer
,
sceneId
,
event
.
getDestination
());
if
(!
result
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.exists_error"
));
}
else
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.success"
,
targetPlayer
.
getNickname
(),
Float
.
toString
(
x
),
Float
.
toString
(
y
),
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.success"
,
targetPlayer
.
getNickname
(),
Float
.
toString
(
x
),
Float
.
toString
(
y
),
Float
.
toString
(
z
),
Integer
.
toString
(
sceneId
))
);
}
...
...
src/main/java/emu/grasscutter/game/managers/mapmark/MapMarksManager.java
View file @
f6b4016f
...
...
@@ -4,6 +4,7 @@ import emu.grasscutter.game.player.Player;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq.Operation
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.server.packet.send.PacketMarkMapRsp
;
import
emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify
;
import
emu.grasscutter.utils.Position
;
...
...
@@ -74,17 +75,21 @@ public class MapMarksManager {
}
private
void
teleport
(
Player
player
,
MapMark
mapMark
)
{
float
y
;
try
{
float
y
;
try
{
y
=
(
float
)
Integer
.
parseInt
(
mapMark
.
getName
());
}
catch
(
Exception
e
)
{
y
=
300
;
}
Position
pos
=
mapMark
.
getPosition
();
player
.
getPos
().
set
(
pos
.
getX
(),
y
,
pos
.
getZ
());
PlayerTeleportEvent
event
=
new
PlayerTeleportEvent
(
player
,
PlayerTeleportEvent
.
TeleportType
.
MAP
,
player
.
getPos
(),
new
Position
(
pos
.
getX
(),
y
,
pos
.
getZ
()));
event
.
call
();
if
(
event
.
isCanceled
())
return
;
player
.
getPos
().
set
(
event
.
getDestination
());
if
(
mapMark
.
getSceneId
()
!=
player
.
getSceneId
())
{
player
.
getWorld
().
transferPlayerToScene
(
player
,
mapMark
.
getSceneId
(),
player
.
getPos
());
}
player
.
getScene
().
broadcastPacket
(
new
PacketSceneEntityAppearNotify
(
player
));
}
player
.
getScene
().
broadcastPacket
(
new
PacketSceneEntityAppearNotify
(
player
));
}
}
src/main/java/emu/grasscutter/server/event/player/PlayerTeleportEvent.java
0 → 100644
View file @
f6b4016f
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
;
public
final
class
PlayerTeleportEvent
extends
PlayerEvent
implements
Cancellable
{
private
final
TeleportType
type
;
private
final
Position
from
;
private
Position
to
;
public
PlayerTeleportEvent
(
Player
player
,
TeleportType
type
,
Position
from
,
Position
to
)
{
super
(
player
);
this
.
type
=
type
;
this
.
from
=
from
;
this
.
to
=
to
;
}
public
TeleportType
getTeleportType
()
{
return
this
.
type
;
}
public
Position
getSource
()
{
return
this
.
from
;
}
public
Position
getDestination
()
{
return
this
.
to
;
}
public
void
setDestination
(
Position
to
)
{
this
.
to
=
to
;
}
public
enum
TeleportType
{
/**
* The player has asked to teleport to a waypoint.
*/
WAYPOINT
,
/**
* The player has asked to teleport using the map.
*/
MAP
,
/**
* The player has asked to teleport using the command.
*/
COMMAND
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java
View file @
f6b4016f
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.binout.ScenePointEntry
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq
;
import
emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp
;
import
emu.grasscutter.utils.Position
;
@Opcodes
(
PacketOpcodes
.
SceneTransToPointReq
)
public
class
HandlerSceneTransToPointReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
SceneTransToPointReq
req
=
SceneTransToPointReq
.
parseFrom
(
payload
);
String
code
=
req
.
getSceneId
()
+
"_"
+
req
.
getPointId
();
ScenePointEntry
scenePointEntry
=
GameData
.
getScenePointEntries
().
get
(
code
);
if
(
scenePointEntry
!=
null
)
{
float
x
=
scenePointEntry
.
getPointData
().
getTranPos
().
getX
();
float
y
=
scenePointEntry
.
getPointData
().
getTranPos
().
getY
();
float
z
=
scenePointEntry
.
getPointData
().
getTranPos
().
getZ
();
session
.
getPlayer
().
getWorld
().
transferPlayerToScene
(
session
.
getPlayer
(),
req
.
getSceneId
(),
new
Position
(
x
,
y
,
z
));
session
.
send
(
new
PacketSceneTransToPointRsp
(
session
.
getPlayer
(),
req
.
getPointId
(),
req
.
getSceneId
()));
}
else
{
session
.
send
(
new
PacketSceneTransToPointRsp
());
}
}
}
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.binout.ScenePointEntry
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq
;
import
emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp
;
import
emu.grasscutter.utils.Position
;
@Opcodes
(
PacketOpcodes
.
SceneTransToPointReq
)
public
class
HandlerSceneTransToPointReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
SceneTransToPointReq
req
=
SceneTransToPointReq
.
parseFrom
(
payload
);
String
code
=
req
.
getSceneId
()
+
"_"
+
req
.
getPointId
();
ScenePointEntry
scenePointEntry
=
GameData
.
getScenePointEntries
().
get
(
code
);
if
(
scenePointEntry
!=
null
)
{
float
x
=
scenePointEntry
.
getPointData
().
getTranPos
().
getX
();
float
y
=
scenePointEntry
.
getPointData
().
getTranPos
().
getY
();
float
z
=
scenePointEntry
.
getPointData
().
getTranPos
().
getZ
();
PlayerTeleportEvent
event
=
new
PlayerTeleportEvent
(
session
.
getPlayer
(),
PlayerTeleportEvent
.
TeleportType
.
WAYPOINT
,
session
.
getPlayer
().
getPos
(),
new
Position
(
x
,
y
,
z
));
event
.
call
();
if
(!
event
.
isCanceled
())
{
session
.
getPlayer
().
getWorld
().
transferPlayerToScene
(
session
.
getPlayer
(),
req
.
getSceneId
(),
new
Position
(
x
,
y
,
z
));
session
.
send
(
new
PacketSceneTransToPointRsp
(
session
.
getPlayer
(),
req
.
getPointId
(),
req
.
getSceneId
()));
}
}
else
{
session
.
send
(
new
PacketSceneTransToPointRsp
());
}
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java
View file @
f6b4016f
...
...
@@ -9,6 +9,7 @@ import emu.grasscutter.net.packet.PacketHandler;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.TryEnterHomeReqOuterClass
;
import
emu.grasscutter.scripts.data.SceneConfig
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketTryEnterHomeRsp
;
import
emu.grasscutter.utils.Position
;
...
...
@@ -38,13 +39,17 @@ public class HandlerTryEnterHomeReq extends PacketHandler {
Scene
scene
=
session
.
getPlayer
().
getWorld
().
getSceneById
(
realmId
);
Position
pos
=
scene
.
getScriptManager
().
getConfig
().
born_pos
;
session
.
getPlayer
().
getWorld
().
transferPlayerToScene
(
session
.
getPlayer
(),
realmId
,
pos
);
PlayerTeleportEvent
event
=
new
PlayerTeleportEvent
(
session
.
getPlayer
(),
PlayerTeleportEvent
.
TeleportType
.
WAYPOINT
,
session
.
getPlayer
().
getPos
(),
pos
);
event
.
call
();
if
(!
event
.
isCanceled
())
{
session
.
getPlayer
().
getWorld
().
transferPlayerToScene
(
session
.
getPlayer
(),
realmId
,
event
.
getDestination
()
);
session
.
send
(
new
PacketTryEnterHomeRsp
(
req
.
getTargetUid
()));
session
.
send
(
new
PacketTryEnterHomeRsp
(
req
.
getTargetUid
()));
}
}
}
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