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
Show 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;
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
import
java.util.List
;
import
java.util.List
;
...
@@ -23,9 +24,14 @@ public final class TeleportAllCommand implements CommandHandler {
...
@@ -23,9 +24,14 @@ 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
.
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"
));
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;
...
@@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
import
java.util.List
;
import
java.util.List
;
...
@@ -54,7 +55,11 @@ public final class TeleportCommand implements CommandHandler {
...
@@ -54,7 +55,11 @@ public final class TeleportCommand implements CommandHandler {
}
}
Position
target_pos
=
new
Position
(
x
,
y
,
z
);
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
)
{
if
(!
result
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.exists_error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.exists_error"
));
}
else
{
}
else
{
...
...
src/main/java/emu/grasscutter/game/managers/mapmark/MapMarksManager.java
View file @
f6b4016f
...
@@ -4,6 +4,7 @@ import emu.grasscutter.game.player.Player;
...
@@ -4,6 +4,7 @@ import emu.grasscutter.game.player.Player;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.net.proto.MapMarkPointTypeOuterClass.MapMarkPointType
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq
;
import
emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq.Operation
;
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.PacketMarkMapRsp
;
import
emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify
;
import
emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
...
@@ -74,17 +75,21 @@ public class MapMarksManager {
...
@@ -74,17 +75,21 @@ public class MapMarksManager {
}
}
private
void
teleport
(
Player
player
,
MapMark
mapMark
)
{
private
void
teleport
(
Player
player
,
MapMark
mapMark
)
{
float
y
;
float
y
;
try
{
try
{
y
=
(
float
)
Integer
.
parseInt
(
mapMark
.
getName
());
y
=
(
float
)
Integer
.
parseInt
(
mapMark
.
getName
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
y
=
300
;
y
=
300
;
}
}
Position
pos
=
mapMark
.
getPosition
();
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
())
{
if
(
mapMark
.
getSceneId
()
!=
player
.
getSceneId
())
{
player
.
getWorld
().
transferPlayerToScene
(
player
,
mapMark
.
getSceneId
(),
player
.
getPos
());
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
...
@@ -7,6 +7,7 @@ import emu.grasscutter.net.packet.PacketOpcodes;
...
@@ -7,6 +7,7 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import
emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq
;
import
emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq
;
import
emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp
;
import
emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp
;
import
emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
...
@@ -26,8 +27,14 @@ public class HandlerSceneTransToPointReq extends PacketHandler {
...
@@ -26,8 +27,14 @@ public class HandlerSceneTransToPointReq extends PacketHandler {
float
y
=
scenePointEntry
.
getPointData
().
getTranPos
().
getY
();
float
y
=
scenePointEntry
.
getPointData
().
getTranPos
().
getY
();
float
z
=
scenePointEntry
.
getPointData
().
getTranPos
().
getZ
();
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
.
getPlayer
().
getWorld
().
transferPlayerToScene
(
session
.
getPlayer
(),
req
.
getSceneId
(),
new
Position
(
x
,
y
,
z
));
session
.
send
(
new
PacketSceneTransToPointRsp
(
session
.
getPlayer
(),
req
.
getPointId
(),
req
.
getSceneId
()));
session
.
send
(
new
PacketSceneTransToPointRsp
(
session
.
getPlayer
(),
req
.
getPointId
(),
req
.
getSceneId
()));
}
}
else
{
}
else
{
session
.
send
(
new
PacketSceneTransToPointRsp
());
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;
...
@@ -9,6 +9,7 @@ import emu.grasscutter.net.packet.PacketHandler;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.TryEnterHomeReqOuterClass
;
import
emu.grasscutter.net.proto.TryEnterHomeReqOuterClass
;
import
emu.grasscutter.scripts.data.SceneConfig
;
import
emu.grasscutter.scripts.data.SceneConfig
;
import
emu.grasscutter.server.event.player.PlayerTeleportEvent
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketTryEnterHomeRsp
;
import
emu.grasscutter.server.packet.send.PacketTryEnterHomeRsp
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
...
@@ -38,13 +39,17 @@ public class HandlerTryEnterHomeReq extends PacketHandler {
...
@@ -38,13 +39,17 @@ public class HandlerTryEnterHomeReq extends PacketHandler {
Scene
scene
=
session
.
getPlayer
().
getWorld
().
getSceneById
(
realmId
);
Scene
scene
=
session
.
getPlayer
().
getWorld
().
getSceneById
(
realmId
);
Position
pos
=
scene
.
getScriptManager
().
getConfig
().
born_pos
;
Position
pos
=
scene
.
getScriptManager
().
getConfig
().
born_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
().
getWorld
().
transferPlayerToScene
(
session
.
getPlayer
(),
session
.
getPlayer
(),
realmId
,
realmId
,
event
.
getDestination
()
pos
);
);
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