mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 08:43:30 +00:00
Fix player pausing
This commit is contained in:
parent
bb693cd222
commit
8438e94c6e
@ -771,7 +771,7 @@ public class Player implements PlayerHook {
|
||||
}
|
||||
|
||||
public void setPaused(boolean newPauseState) {
|
||||
boolean oldPauseState = this.paused;
|
||||
var oldPauseState = this.paused;
|
||||
this.paused = newPauseState;
|
||||
|
||||
if (newPauseState && !oldPauseState) {
|
||||
@ -1498,8 +1498,10 @@ public class Player implements PlayerHook {
|
||||
PropChangeReason.PROP_CHANGE_REASON_PLAYER_ADD_EXP));
|
||||
case PROP_PLAYER_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
||||
PropChangeReason.PROP_CHANGE_REASON_LEVELUP));
|
||||
case PROP_PLAYER_WORLD_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
||||
PropChangeReason.PROP_CHANGE_REASON_MANUAL_ADJUST_WORLD_LEVEL));
|
||||
|
||||
// TODO: Handle world level changing.
|
||||
// case PROP_PLAYER_WORLD_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
||||
// PropChangeReason.PROP_CHANGE_REASON_MANUAL_ADJUST_WORLD_LEVEL));
|
||||
}
|
||||
|
||||
// Update player with packet.
|
||||
|
@ -1,7 +1,5 @@
|
||||
package emu.grasscutter.game.world;
|
||||
|
||||
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
|
||||
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.excels.dungeon.DungeonData;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
@ -24,13 +22,17 @@ import emu.grasscutter.utils.Position;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
|
||||
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
|
||||
|
||||
public final class World implements Iterable<Player> {
|
||||
@Getter private final GameServer server;
|
||||
@ -477,7 +479,12 @@ public final class World implements Iterable<Player> {
|
||||
* @param paused True if the world should be paused.
|
||||
*/
|
||||
public void setPaused(boolean paused) {
|
||||
this.getWorldTime(); // Update the world time.
|
||||
// Check if this world is a multiplayer world.
|
||||
if (this.isMultiplayer) return;
|
||||
|
||||
// Update the world time.
|
||||
this.getWorldTime();
|
||||
this.updateTime();
|
||||
|
||||
// If the world is being un-paused, update the last update time.
|
||||
if (this.isPaused != paused && !paused) {
|
||||
@ -526,6 +533,16 @@ public final class World implements Iterable<Player> {
|
||||
player -> player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all players of the current world time.
|
||||
*/
|
||||
public void updateTime() {
|
||||
this.getPlayers().forEach(p ->
|
||||
p.sendPacket(new PacketPlayerGameTimeNotify(p)));
|
||||
this.getPlayers().forEach(p ->
|
||||
p.sendPacket(new PacketSceneTimeNotify(p)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks the world time.
|
||||
*
|
||||
@ -535,10 +552,12 @@ public final class World implements Iterable<Player> {
|
||||
this.timeLocked = locked;
|
||||
|
||||
// Notify players of the locking.
|
||||
this.updateTime();
|
||||
this.getPlayers()
|
||||
.forEach(player -> player.setProperty(PlayerProperty.PROP_IS_GAME_TIME_LOCKED, locked));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Player> iterator() {
|
||||
return this.getPlayers().iterator();
|
||||
|
@ -4,22 +4,25 @@ import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.PlayerSetPauseReqOuterClass.PlayerSetPauseReq;
|
||||
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketPlayerSetPauseRsp;
|
||||
import emu.grasscutter.server.packet.send.PacketPlayerTimeNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneTimeNotify;
|
||||
|
||||
@Opcodes(PacketOpcodes.PlayerSetPauseReq)
|
||||
public class HandlerPlayerSetPauseReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
PlayerSetPauseReq req = PlayerSetPauseReq.parseFrom(payload);
|
||||
var req = PlayerSetPauseReq.parseFrom(payload);
|
||||
var player = session.getPlayer();
|
||||
var world = player.getWorld();
|
||||
|
||||
session.send(new PacketPlayerSetPauseRsp());
|
||||
session.getPlayer().setPaused(req.getIsPaused());
|
||||
|
||||
session.send(new PacketPlayerTimeNotify(session.getPlayer()));
|
||||
session.send(new PacketSceneTimeNotify(session.getPlayer()));
|
||||
// Check if the player is in a multiplayer world.
|
||||
if (player.isInMultiplayer()) {
|
||||
session.send(new PacketPlayerSetPauseRsp(Retcode.RET_FAIL));
|
||||
} else {
|
||||
world.setPaused(req.getIsPaused());
|
||||
session.send(new PacketPlayerSetPauseRsp(Retcode.RET_SUCC));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
||||
|
||||
public class PacketPlayerSetPauseRsp extends BasePacket {
|
||||
|
||||
public PacketPlayerSetPauseRsp() {
|
||||
public PacketPlayerSetPauseRsp(Retcode retcode) {
|
||||
super(PacketOpcodes.PlayerSetPauseRsp);
|
||||
|
||||
this.setData(PlayerSetPauseRsp.newBuilder().setRetcode(Retcode.RET_SUCC_VALUE));
|
||||
this.setData(PlayerSetPauseRsp.newBuilder()
|
||||
.setRetcode(retcode.getNumber()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user