Fix hand recording

This commit is contained in:
fullwall 2024-01-26 23:43:50 +08:00
parent c3791d162f
commit 44e68147ab
1 changed files with 6 additions and 9 deletions

View File

@ -273,7 +273,7 @@ public class CommandTrait extends Trait {
command -> (command.hand == hand || command.hand == Hand.BOTH))); command -> (command.hand == hand || command.hand == Hand.BOTH)));
if (executionMode == ExecutionMode.RANDOM) { if (executionMode == ExecutionMode.RANDOM) {
if (commandList.size() > 0) { if (commandList.size() > 0) {
runCommand(player, commandList.get(Util.getFastRandom().nextInt(commandList.size()))); runCommand(player, hand, commandList.get(Util.getFastRandom().nextInt(commandList.size())));
} }
return; return;
} }
@ -299,17 +299,13 @@ public class CommandTrait extends Trait {
info.lastUsedId = -1; info.lastUsedId = -1;
} }
} }
runCommand(player, command); runCommand(player, hand, command);
if (executionMode == ExecutionMode.SEQUENTIAL
&& (info = playerTracking.get(player.getUniqueId())) != null) {
info.lastUsedHand = hand;
}
if (executionMode == ExecutionMode.SEQUENTIAL || (charged != null && !charged)) if (executionMode == ExecutionMode.SEQUENTIAL || (charged != null && !charged))
break; break;
} }
} }
private void runCommand(Player player, NPCCommand command) { private void runCommand(Player player, Hand hand, NPCCommand command) {
Runnable runnable = () -> { Runnable runnable = () -> {
PlayerNPCCommand info = playerTracking.get(player.getUniqueId()); PlayerNPCCommand info = playerTracking.get(player.getUniqueId());
if (info == null && (executionMode == ExecutionMode.SEQUENTIAL if (info == null && (executionMode == ExecutionMode.SEQUENTIAL
@ -324,7 +320,7 @@ public class CommandTrait extends Trait {
return; return;
} }
} }
if (info != null && !info.canUse(CommandTrait.this, player, command)) if (info != null && !info.canUse(CommandTrait.this, player, hand, command))
return; return;
if (charged == null) { if (charged == null) {
@ -779,7 +775,7 @@ public class CommandTrait extends Trait {
public PlayerNPCCommand() { public PlayerNPCCommand() {
} }
public boolean canUse(CommandTrait trait, Player player, NPCCommand command) { public boolean canUse(CommandTrait trait, Player player, Hand hand, NPCCommand command) {
for (String perm : command.perms) { for (String perm : command.perms) {
if (!player.hasPermission(perm)) { if (!player.hasPermission(perm)) {
trait.sendErrorMessage(player, CommandTraitError.NO_PERMISSION, null); trait.sendErrorMessage(player, CommandTraitError.NO_PERMISSION, null);
@ -828,6 +824,7 @@ public class CommandTrait extends Trait {
nUsed.put(commandKey, timesUsed + 1); nUsed.put(commandKey, timesUsed + 1);
} }
lastUsedId = command.id; lastUsedId = command.id;
lastUsedHand = hand;
return true; return true;
} }