48 lines
2.0 KiB
Java
48 lines
2.0 KiB
Java
/*
|
|
* *
|
|
* * Copyright (c) 2025 R3944Realms. All rights reserved.
|
|
* *
|
|
* * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
|
* * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
* * or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
|
|
* *
|
|
* * 本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
|
|
*
|
|
*/
|
|
|
|
package top.r3944realms.eroticdungeongame.content.capability;
|
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import top.r3944realms.eroticdungeongame.content.register.EDGCapabilities;
|
|
import top.r3944realms.lib39.core.event.CommonEventHandler;
|
|
import top.r3944realms.lib39.core.sync.CachedSyncManager;
|
|
|
|
import java.util.*;
|
|
|
|
public class DungeonDataSyncManager extends CachedSyncManager<UUID, AbstractPlayerDungeonData> {
|
|
public static Map<UUID, AbstractPlayerDungeonData> playerDungeonData = new HashMap<>();
|
|
@Override
|
|
public Map<UUID, AbstractPlayerDungeonData> getSyncMap() {
|
|
return playerDungeonData;
|
|
}
|
|
|
|
@Nullable
|
|
public AbstractPlayerDungeonData getPlayerDungeonData(UUID uuid) {
|
|
return playerDungeonData.get(uuid);
|
|
}
|
|
public void removePlayerSeatEntity(UUID uuid) {
|
|
try {
|
|
Optional<AbstractPlayerDungeonData> abstractPlayerDungeonData = Optional.ofNullable(CommonEventHandler.Game.getServerLevel())
|
|
.map(i -> i.getEntity(uuid))
|
|
.map(i -> i.getCapability(EDGCapabilities.PLAYER_DUNGEON_DATA_CAP))
|
|
.map(LazyOptional::resolve)
|
|
.map(Optional::orElseThrow);
|
|
abstractPlayerDungeonData
|
|
.ifPresent(AbstractPlayerDungeonData::removeSeatEntityId);
|
|
abstractPlayerDungeonData
|
|
.ifPresent(AbstractPlayerDungeonData::removeSeatAnimId);
|
|
} catch (NoSuchElementException ignored) {}
|
|
}
|
|
}
|