refactor: 修改释放玩家接口及其调用,添加强制退出参数

This commit is contained in:
叁玖领域 2026-03-04 17:04:36 +08:00
parent ccb3146a0c
commit 6561ab393a
5 changed files with 16 additions and 9 deletions

View File

@ -88,7 +88,7 @@ public class DungeonDataSyncManager extends CachedSyncManager<UUID, AbstractPlay
player.getCapability(EroticDungeonGameApi.PLAYER_DUNGEON_DATA_CAP).ifPresent(
cap -> {
if (cap.getDeviceMainBlockPos() != null && player.level().getBlockEntity(cap.getDeviceMainBlockPos()) instanceof BaseSeatBlockEntity seat) {
((IEDGEntity)player).releaseEntityFromEDGDevice(seat.getLockCode());
((IEDGEntity)player).releaseEntityFromEDGDevice(true);
FurnitureHelper.setSeatOccupied(player.level(), cap.getDeviceMainBlockPos(), false);
}
}

View File

@ -153,7 +153,7 @@ public class SeatService {
}
}
} else if (deviceMainBlockPos != null && player.level().getBlockEntity(cap.getDeviceMainBlockPos()) instanceof BaseSeatBlockEntity seat) {
((IEDGEntity)player).releaseEntityFromEDGDevice(seat.getLockCode());
((IEDGEntity)player).releaseEntityFromEDGDevice(true);
try {
if (bindPlayerToSeat(player, deviceMainBlockPos)) {
return player.getVehicle();
@ -262,7 +262,7 @@ public class SeatService {
}
isCancelled = EroticDungeon.EVENT_BUS.post(new UnRideDeviceEvent.Pre(playerByUUID, blockPos, blockState, be, seat));
if (!isCancelled) {
if(seat != null) ((IEDGEntity)(playerByUUID)).releaseEntityFromEDGDevice(be.getLockCode());
if(seat != null) ((IEDGEntity)(playerByUUID)).releaseEntityFromEDGDevice(true);
playerByUUID.getCapability(EroticDungeonGameApi.PLAYER_DUNGEON_DATA_CAP)
.ifPresent(i -> i.clearDungeonData(playerByUUID));
} else {

View File

@ -105,11 +105,11 @@ public abstract class MixinEntity implements IEDGEntity {
@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public void releaseEntityFromEDGDevice(long lock) {
public void releaseEntityFromEDGDevice(long lock, boolean forced) {
Services.WORK_SPACE.tryToDoIfInDevice(Entity.class.cast(this),
data -> {
if (data.getDeviceMainBlockPos() != null && level.getBlockEntity(data.getDeviceMainBlockPos()) instanceof BaseSeatBlockEntity seatBe) {
if ((Entity.class.cast(this) instanceof Player player && player.isCreative()) || (seatBe.hasLockCode() && Objects.equals(seatBe.getLockCode(), lock)) || !seatBe.hasLockCode()) {
if ((Entity.class.cast(this) instanceof Player player && player.isCreative()) || forced || (seatBe.hasLockCode() && Objects.equals(seatBe.getLockCode(), lock)) || !seatBe.hasLockCode()) {
removeVehicle();
}
}

View File

@ -76,12 +76,12 @@ public abstract class MixinServerPlayer extends Player implements IEDGEntity {
@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public void releaseEntityFromEDGDevice(long lock) {
public void releaseEntityFromEDGDevice(long lock, boolean forced) {
ServerPlayer player = ServerPlayer.class.cast(this);
Services.WORK_SPACE.tryToDoIfInDevice(player,
data -> {
if (data.getDeviceMainBlockPos() != null && level().getBlockEntity(data.getDeviceMainBlockPos()) instanceof BaseSeatBlockEntity seatBe) {
if (isCreative() || (seatBe.hasLockCode() && Objects.equals(seatBe.getLockCode(), lock)) || !seatBe.hasLockCode()) {
if (isCreative() || forced || (seatBe.hasLockCode() && Objects.equals(seatBe.getLockCode(), lock)) || !seatBe.hasLockCode()) {
Entity entity = this.getVehicle();
this.removeVehicle();
if (entity != null && entity != this.getVehicle() && !this.level().isClientSide) {

View File

@ -17,9 +17,16 @@
package top.r3944realms.eroticdungeongame.util;
public interface IEDGEntity {
void releaseEntityFromEDGDevice(long lock);
default void releaseEntityFromEDGDevice(long lock) {
releaseEntityFromEDGDevice(lock, false);
}
default void releaseEntityFromEDGDevice(boolean force) {
releaseEntityFromEDGDevice(-1, force);
}
void releaseEntityFromEDGDevice(long lock, boolean force);
default void releaseEntityFromEDGDevice() {
releaseEntityFromEDGDevice(-1);
releaseEntityFromEDGDevice(false);
}
}