mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 04:43:51 +08:00
Add PlayerTeleportEvent
This commit is contained in:
parent
02ca5cf23c
commit
f6b4016f1b
@ -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();
|
||||
|
||||
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
|
||||
Position pos = targetPlayer.getPos();
|
||||
PlayerTeleportEvent event = new PlayerTeleportEvent(targetPlayer, PlayerTeleportEvent.TeleportType.COMMAND,
|
||||
targetPlayer.getPos(), pos);
|
||||
event.call();
|
||||
|
||||
if(!event.isCanceled())
|
||||
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), event.getDestination());
|
||||
}
|
||||
|
||||
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.teleportAll.success"));
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -1,36 +1,43 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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(
|
||||
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,
|
||||
pos
|
||||
);
|
||||
realmId, event.getDestination()
|
||||
);
|
||||
|
||||
|
||||
session.send(new PacketTryEnterHomeRsp(req.getTargetUid()));
|
||||
session.send(new PacketTryEnterHomeRsp(req.getTargetUid()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user