Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderscoreTud committed Nov 8, 2024
1 parent c46cb8a commit 2ce9736
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
public boolean check(Event event) {
Player eventPlayer = !past && event instanceof PlayerInputEvent inputEvent ? inputEvent.getPlayer() : null;
Player eventPlayer = event instanceof PlayerInputEvent inputEvent ? inputEvent.getPlayer() : null;
InputKey[] inputKeys = this.inputKeys.getAll(event);
boolean and = this.inputKeys.getAnd();
return players.check(event, player -> {
Input input;
if (player.equals(eventPlayer)) {
// If we want to get the new input of the event-player, we must get it from the event
if (!past && player.equals(eventPlayer)) {
input = ((PlayerInputEvent) event).getInput();
} else {
} else { // Otherwise, we get the current (or past in case of an event-player) input
input = player.getCurrentInput();
}
return CollectionUtils.check(inputKeys, inputKey -> inputKey.check(input), and);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class EvtPlayerInput extends SkriptEvent {

static {
Skript.registerEvent("Player Input", EvtPlayerInput.class, PlayerInputEvent.class,
"[player] (toggle|toggling|1:press[ing]|2:release|2:releasing) [of] (%-inputkeys%|[a|any] key)",
"([player] %-inputkeys%|[a|any] [player] key) (toggle|toggling|1:press[ing]|2:releas(e|ing))")
"[player] (toggle|toggling|1:press[ing]|2:release|2:releasing) [of] (%-inputkeys%|[a|any] input key)",
"([player] %-inputkeys%|[a|any] [player] input key) (toggle|toggling|1:press[ing]|2:releas(e|ing))")
.description("Called when a player sends an updated input to the server.",
"Note: The input keys event value is the set of keys the player is currently pressing, not the keys that were pressed or released.")
.examples("on player press any key:",
.examples("on player press any input key:",
"\tsend \"You are pressing: %event-inputkeys%\" to player")
.since("INSERT VERSION")
.requiredPlugins("Minecraft 1.21.3+");
Expand Down Expand Up @@ -52,7 +52,7 @@ public String toString(@Nullable Event event, boolean debug) {
builder.append("player ");
builder.append(type.name().toLowerCase());
builder.append(" ");
builder.append(keysToCheck == null ? "any key" : keysToCheck.toString(event, debug));
builder.append(keysToCheck == null ? "any input key" : keysToCheck.toString(event, debug));
return builder.toString();
}

Expand Down Expand Up @@ -98,14 +98,14 @@ public boolean checkKeyState(boolean inPrevious, boolean inCurrent) {
* @return true if the condition is met based on the input type, false otherwise
*/
public boolean checkInputKeys(Set<InputKey> previous, Set<InputKey> current, @Nullable Set<InputKey> keysToCheck, boolean and) {
if (keysToCheck == null) {
if (keysToCheck == null) {
return switch (this) {
case TOGGLE -> true;
case PRESS -> previous.size() <= current.size();
case RELEASE -> previous.size() >= current.size();
};
}
for (InputKey key : keysToCheck) {
for (InputKey key : keysToCheck) {
boolean inPrevious = previous.contains(key);
boolean inCurrent = current.contains(key);
if (and && !checkKeyState(inPrevious, inCurrent)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private Input fromKeys(InputKey... keys) {
case JUMP -> EasyMock.expect(input.isJump()).andReturn(true);
case SNEAK -> EasyMock.expect(input.isSneak()).andReturn(true);
case SPRINT -> EasyMock.expect(input.isSprint()).andReturn(true);
}
}
}
EasyMock.replay(input);
return input;
Expand Down
2 changes: 1 addition & 1 deletion src/test/skript/junit/EvtPlayerInput.sk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test "EvtPlayerInputJUnit" when running JUnit:

ensure junit test "org.skriptlang.skript.test.tests.syntaxes.events.EvtPlayerInputTest" completes {_tests::*}

on toggle of any key:
on toggle of any input key:
set {_test} to "org.skriptlang.skript.test.tests.syntaxes.events.EvtPlayerInputTest"
junit test is {_test}

Expand Down

0 comments on commit 2ce9736

Please sign in to comment.