Fix player pausing

This commit is contained in:
KingRainbow44
2023-05-18 02:54:47 -04:00
parent bb693cd222
commit 8438e94c6e
4 changed files with 43 additions and 18 deletions

View File

@@ -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.

View File

@@ -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();