Skip to content

Commit

Permalink
Merge branch 'dev/patch' into fish-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeezburga authored Jan 28, 2025
2 parents a30af44 + 5c2ce78 commit 90c98c4
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/main/java/ch/njol/skript/effects/EffConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class EffConnect extends Effect {

static {
Skript.registerEffect(EffConnect.class,
"(send|connect) %players% to [proxy|bungeecord] [server] %string%",
"connect %players% to [proxy|bungeecord] [server] %string%",
"send %players% to [proxy|bungeecord] server %string%",
"transfer %players% to server %string% [on port %-number%]"
);
}
Expand All @@ -51,7 +52,7 @@ public class EffConnect extends Effect {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
players = (Expression<Player>) exprs[0];
server = (Expression<String>) exprs[1];
transfer = matchedPattern == 1;
transfer = matchedPattern == 2;

if (transfer) {
port = (Expression<Number>) exprs[2];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/sections/SecFor.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean init(Expression<?>[] exprs,
}
//</editor-fold>
this.loadOptionalCode(sectionNode);
super.setNext(this);
this.setInternalNext(this);
return true;
}

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/ch/njol/skript/sections/SecLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public boolean init(Expression<?>[] exprs,

guaranteedToLoop = guaranteedToLoop(expression);
loadOptionalCode(sectionNode);
super.setNext(this);
this.setInternalNext(this);

return true;
}
Expand All @@ -130,11 +130,11 @@ public boolean init(Expression<?>[] exprs,
if (iter == null) {
if (iterableSingle) {
Object value = expression.getSingle(event);
if (value instanceof Iterable<?> iterable) {
iter = iterable.iterator();
// Guaranteed to be ordered so we try it first
} else if (value instanceof Container<?> container) {
if (value instanceof Container<?> container) {
// Container may have special behaviour over regular iterator
iter = container.containerIterator();
} else if (value instanceof Iterable<?> iterable) {
iter = iterable.iterator();
} else {
iter = Collections.singleton(value).iterator();
}
Expand Down Expand Up @@ -210,6 +210,13 @@ public SecLoop setNext(@Nullable TriggerItem next) {
return this;
}

/**
* @see LoopSection#setNext(TriggerItem)
*/
protected void setInternalNext(TriggerItem item) {
super.setNext(item);
}

@Nullable
@Override
public TriggerItem getActualNext() {
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/skriptlang/skript/lang/util/SkriptQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,21 @@ public Object[] removeRangeSafely(int fromIndex, int toIndex) {

@Override
public Iterator<Object> containerIterator() {
return this.iterator();
return new Iterator<>() {
@Override
public boolean hasNext() {
return !SkriptQueue.this.isEmpty();
}

@Override
public Object next() {
return SkriptQueue.this.pollFirst();
}

@Override
public void remove() {
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.skriptlang.skript.test.tests.regression;

import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.lang.util.ContextlessEvent;
import ch.njol.skript.test.runner.SkriptJUnitTest;
import ch.njol.skript.variables.Variables;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class EffSendEffConnectConflict7517Test extends SkriptJUnitTest {

private static final String MESSAGE = "Hello, world!";

private CommandSender sender;
private Effect sendEffect;

@Before
public void setup() {
sender = EasyMock.niceMock(CommandSender.class);
sendEffect = Effect.parse("send {_message} to {_sender}", null);
if (sendEffect == null)
throw new IllegalStateException();
}

@Test
public void test() {
Event event = ContextlessEvent.get();
Variables.setVariable("sender", sender, event, true);
Variables.setVariable("message", MESSAGE, event, true);

Capture<String> messageCapture = EasyMock.newCapture();
sender.sendMessage(EasyMock.capture(messageCapture));
EasyMock.replay(sender);

TriggerItem.walk(sendEffect, event);
EasyMock.verify(sender);
Assert.assertEquals(MESSAGE, messageCapture.getValue());
}

}
17 changes: 17 additions & 0 deletions src/test/skript/tests/regressions/7536-for-loop-ending.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using for each loops

test "for each loops ending (start)":
clear {7536 For Each::*}
for each {_word} in ("test", "test2"):
add {_word} to {7536 For Each::*}
for each {_word 2} in ("example", "example2"):
add {_word 2} to {7536 For Each::*}

assert the size of {7536 For Each::*} is 6 with "Wrong number of variables: %{7536 For Each::*}%"

# Need to make sure that trigger didn't just die
test "for each loops ending (result)":
assert the size of {7536 For Each::*} is 6 with "Wrong number of variables: %{7536 For Each::*}%"
assert {7536 For Each::*} is ("test", "example", "example2", "test2", "example", "example2") with "Wrong loop order: %{7536 For Each::*}%"

delete {7536 For Each::*}
6 changes: 5 additions & 1 deletion src/test/skript/tests/syntaxes/expressions/ExprColorOf.sk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ test "color of displays":
spawn a text display at spawn of world "world":
set {_e} to entity

assert color of {_e} is rgb(0,0,0, 64) with "default background colour failed"
if running minecraft "1.21.4":
# Paper changed return behaviour in 1.21.4#125
assert color of {_e} is not set with "default background colour failed"
else:
assert color of {_e} is rgb(0,0,0, 64) with "default background colour failed"

set colour of {_e} to red
assert color of {_e} is red with "failed to set background colour"
Expand Down
4 changes: 4 additions & 0 deletions src/test/skript/tests/syntaxes/sections/SecFor.sk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test "for section":
delete {_value}

for {_key}, {_value} in {_list::*}:
set {_key} to {_key} parsed as integer
assert {_key} is greater than 0 with "Expected key > 0, found %{_key}%"
assert {_key} is less than 4 with "Expected key < 4, found %{_key}%"
assert {_value} is greater than 0 with "Expected value > 0, found %{_value}%"
Expand All @@ -27,6 +28,7 @@ test "for section":


for key {_key} and value {_value} in {_list::*}:
set {_key} to {_key} parsed as integer
assert {_key} is greater than 0 with "Expected key > 0, found %{_key}%"
assert {_key} is less than 4 with "Expected key < 4, found %{_key}%"
assert {_value} is greater than 0 with "Expected value > 0, found %{_value}%"
Expand All @@ -38,6 +40,7 @@ test "for section":
delete {_value}

for {_key} and {_value} in {_list::*}:
set {_key} to {_key} parsed as integer
assert {_key} is greater than 0 with "Expected key > 0, found %{_key}%"
assert {_key} is less than 4 with "Expected key < 4, found %{_key}%"
assert {_value} is greater than 0 with "Expected value > 0, found %{_value}%"
Expand All @@ -50,6 +53,7 @@ test "for section":

# 'loop' syntax alternative
loop {_key} and {_value} in {_list::*}:
set {_key} to {_key} parsed as integer
assert {_key} is greater than 0 with "Expected key > 0, found %{_key}%"
assert {_key} is less than 4 with "Expected key < 4, found %{_key}%"
assert {_value} is greater than 0 with "Expected value > 0, found %{_value}%"
Expand Down

0 comments on commit 90c98c4

Please sign in to comment.