Skip to content

Commit

Permalink
misc: 一些调整
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 13, 2023
1 parent 445e744 commit bf5cbfa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 51 deletions.
100 changes: 53 additions & 47 deletions src/main/java/xiamomc/morph/events/InteractionMirrorProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public void onPlayerHurtEntity(EntityDamageByEntityEvent e)
@Resolved
private PlayerTracker tracker;

/**
* todo: SwingEvent应当只相应方块破坏
*/
@EventHandler
public void onPlayerSwing(PlayerArmSwingEvent e)
{
Expand All @@ -215,6 +218,7 @@ public void onPlayerSwing(PlayerArmSwingEvent e)

var playerInDistance = playerInDistance(player, inf);

//取消一定条件下源玩家的挥手动画
if (targetPlayer.getLocation().getWorld() == player.getLocation().getWorld()
&& Math.abs(targetPlayer.getLocation().distance(player.getLocation())) <= 6
&& playerInDistance)
Expand All @@ -231,8 +235,15 @@ public void onPlayerSwing(PlayerArmSwingEvent e)

if (!playerInDistance || simStack.contains(targetPlayer)) return;

if (tracker.droppingItemThisTick(player))
//若源玩家正在丢出物品,不要处理
//若源玩家没有在破坏方块,不要处理
//检查玩家在此tick内是否存在互动以避免重复镜像
if (tracker.droppingItemThisTick(player)
|| !tracker.isBreakingSuspect(player)
|| tracker.interactingThisTick(player))
{
return;
}

var lastAction = tracker.getLastInteractAction(player);

Expand All @@ -249,9 +260,6 @@ public void onPlayerSwing(PlayerArmSwingEvent e)
lastAction = PlayerTracker.InteractType.LEFT_CLICK_BLOCK;
}

//检查玩家在此tick内是否存在互动以避免重复镜像
if (tracker.interactingThisTick(player)) return;

simulateOperation(lastAction.toBukkitAction(), targetPlayer, player);
logOperation(player, targetPlayer, lastAction.isLeftClick() ? OperationType.LeftClick : OperationType.RightClick);
}
Expand Down Expand Up @@ -318,59 +326,57 @@ private void clearStackIfPossible(Player player, boolean forceClear)
return;
}

// 清空Stack
// 如果目标实体不是玩家,那么清空simStack
var targetedEntity = player.getTargetEntity(5);
if (targetedEntity instanceof Player targetedPlayer)
if (!(targetedEntity instanceof Player targetedPlayer))
{
simStack.clear();
return;
}

//by_name: 直接清空
//by_sight: 如果下个不是目标,那么清空
var mode = selectionMode.get();
if (mode.equalsIgnoreCase(InteractionMirrorSelectionMode.BY_NAME))
{
simStack.clear();
}
else
{
//by_name: 直接清空
//by_sight: 如果下个不是目标,那么清空
var mode = selectionMode.get();
if (mode.equalsIgnoreCase(InteractionMirrorSelectionMode.BY_NAME))
//logger.info("Is by sight");
var nextSelection = getMirrorTarget(player);
//logger.info("Next sel:" + nextSelection);

// 如果玩家面向的目标不是下一个mirror对象,那么清空栈
if (!targetedPlayer.equals(nextSelection.target))
{
//logger.info("Target not equal, clear");
simStack.clear();
return;
}
else
{
//logger.info("Is by sight");
var nextSelection = getMirrorTarget(player);
//logger.info("Next sel:" + nextSelection);

// 如果玩家面向的目标不是下一个mirror对象,那么清空栈
if (!targetedPlayer.equals(nextSelection.target))
{
//logger.info("Target not equal, clear");
simStack.clear();
return;
}

var targetPlayerTarget = targetedPlayer.getTargetEntity(5);
var targetPlayerTarget = targetedPlayer.getTargetEntity(5);

//if (debugOutput.get())
// logger.info("Target player target:" + targetPlayerTarget);

// 如果面向的玩家没有面向任何东西,那么也清空栈
if (targetPlayerTarget == null)
{
//logger.info("Null target clear");
simStack.clear();
return;
}
//if (debugOutput.get())
// logger.info("Target player target:" + targetPlayerTarget);

// 如果玩家面向的目标也在面向自己,那么清空栈
if (player.equals(targetPlayerTarget))
{
//logger.info("Circular clear");
simStack.clear();
return;
}
// 如果面向的玩家没有面向任何东西,那么也清空栈
if (targetPlayerTarget == null)
{
//logger.info("Null target clear");
simStack.clear();
return;
}

//logger.info("All passes failed");
// 如果玩家面向的目标也在面向自己,那么清空栈
if (player.equals(targetPlayerTarget))
{
//logger.info("Circular clear");
simStack.clear();
return;
}
}
else
{
//logger.info("Outside Null target clear");
simStack.clear();

//logger.info("All passes failed");
}
}

Expand Down
21 changes: 17 additions & 4 deletions src/main/java/xiamomc/morph/misc/PlayerOperationSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import xiamomc.pluginbase.Bindables.Bindable;

import java.util.Map;
import java.util.Objects;

public class PlayerOperationSimulator extends MorphPluginObject
{
Expand Down Expand Up @@ -114,16 +115,18 @@ public SimulateResult simulateLeftClick(Player player)
var targetBlock = traceResult == null ? null : traceResult.getHitBlock();
var targetEntity = traceResult == null ? null : traceResult.getHitEntity();

// 忽略超过实体reach范围的实体
if (targetEntity != null && targetEntity.getLocation().distance(player.getLocation()) > entityReachDistance)
targetEntity = null;

//获取方块破坏信息
var destroyHandler = playerHandlerMap.getOrDefault(player, null);

//如果此时没有目标方块,那么移除此破坏信息的目标
//如果视野内有实体或者不再存在目标方块,那么使destroyHandler重置进度
if ((targetBlock == null || targetEntity != null) && destroyHandler != null)
destroyHandler.changeBlock(null);

//优先攻击实体
//如果目标实体不为null,则攻击该实体
if (targetEntity != null)
{
Expand All @@ -135,18 +138,27 @@ public SimulateResult simulateLeftClick(Player player)
return SimulateResult.success(EquipmentSlot.HAND);
}

//对着空气空挥
//没有实体也没有方块,视为对着空气空挥
//此时不要做任何事情,只返回success来允许播放挥手动画
if (targetBlock == null)
return SimulateResult.success(EquipmentSlot.HAND);

//冒险模式,并且无法破坏目标方块 -> 操作成功(空挥)
//如果玩家处于冒险模式并且无法破坏目标方块,也不要做任何事情,只返回success来允许播放动画
if (player.getGameMode() == GameMode.ADVENTURE)
{
var meta = player.getEquipment().getItemInMainHand().getItemMeta();
var meta = Objects.requireNonNull(player.getEquipment(), "Null equipment?")
.getItemInMainHand().getItemMeta();

if (meta == null || !meta.getDestroyableKeys().contains(targetBlock.getBlockData().getMaterial().getKey()))
return SimulateResult.success(EquipmentSlot.HAND);
}

//=-=-=-=-=-=-=-=-=-=-=-=
//
// 在此开始对方块的处理
//
//=-=-=-=-=-=-=-=-=-=-=-=

//初始化destoryInfo
if (destroyHandler == null)
{
Expand Down Expand Up @@ -218,6 +230,7 @@ public SimulateResult simulateRightClick(Player player)
//获取互动位置
hitPos.subtract(targetEntity.getLocation().toVector());

//轮流尝试左右手
if (this.tryUseItemOnEntity(player, targetEntity, itemInMainHand, InteractionHand.MAIN_HAND, hitPos))
return SimulateResult.success(EquipmentSlot.HAND);

Expand Down

0 comments on commit bf5cbfa

Please sign in to comment.