Skip to content

Commit

Permalink
Merge pull request #7535 from SkriptLang/dev/patch
Browse files Browse the repository at this point in the history
Merge patch into feature.
  • Loading branch information
Moderocky authored Jan 26, 2025
2 parents 9e69c9c + 5c2ce78 commit 2f2f7fc
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ public boolean supportsNameChange() {
@Override
public void setName(String name) {
BlockState state = block.getState();
if (state instanceof Nameable nameable)
if (state instanceof Nameable nameable) {
//noinspection deprecation
nameable.setCustomName(name);
state.update(true, false);
}
}
},
//</editor-fold>
Expand Down
50 changes: 48 additions & 2 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
import ch.njol.skript.util.visual.VisualEffect;
import ch.njol.skript.util.visual.VisualEffects;
import ch.njol.yggdrasil.Fields;
import org.skriptlang.skript.lang.util.SkriptQueue;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.util.SkriptQueue;
import org.skriptlang.skript.util.Executable;

import java.io.File;
import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -731,7 +733,51 @@ public void change(SkriptQueue[] what, Object @Nullable [] delta, ChangeMode mod
}
}
})
.serializer(new YggdrasilSerializer<>())
.parser(new Parser<SkriptQueue>() {

@Override
public boolean canParse(ParseContext context) {
return false;
}

@Override
public String toString(SkriptQueue queue, int flags) {
return Classes.toString(queue.toArray(), flags, true);
}

@Override
public String toVariableNameString(SkriptQueue queue) {
return this.toString(queue, 0);
}

})
.serializer(new Serializer<SkriptQueue>() {
@Override
public Fields serialize(SkriptQueue queue) throws NotSerializableException {
Fields fields = new Fields();
fields.putObject("contents", queue.toArray());
return fields;
}

@Override
public void deserialize(SkriptQueue queue, Fields fields)
throws StreamCorruptedException, NotSerializableException {
Object[] contents = fields.getObject("contents", Object[].class);
queue.clear();
if (contents != null)
queue.addAll(List.of(contents));
}

@Override
public boolean mustSyncDeserialization() {
return false;
}

@Override
protected boolean canBeInstantiated() {
return true;
}
})
);


Expand Down
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
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/expressions/ExprName.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public class ExprName extends SimplePropertyExpression<Object, String> {
serializer = BungeeComponentSerializer.get();

List<String> patterns = new ArrayList<>();
patterns.addAll(Arrays.asList(getPatterns("name[s]", "offlineplayers/entities/inventories/nameds")));
patterns.addAll(Arrays.asList(getPatterns("(display|nick|chat|custom)[ ]name[s]", "offlineplayers/entities/inventories/nameds")));
patterns.addAll(Arrays.asList(getPatterns("name[s]", "offlineplayers/entities/nameds/inventories")));
patterns.addAll(Arrays.asList(getPatterns("(display|nick|chat|custom)[ ]name[s]", "offlineplayers/entities/nameds/inventories")));
patterns.addAll(Arrays.asList(getPatterns("(player|tab)[ ]list name[s]", "players")));

Skript.registerExpression(ExprName.class, String.class, ExpressionType.COMBINED, patterns.toArray(new String[0]));
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
19 changes: 16 additions & 3 deletions src/main/java/org/skriptlang/skript/lang/util/SkriptQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ch.njol.skript.lang.util.common.AnyAmount;
import ch.njol.skript.util.Container;
import ch.njol.yggdrasil.YggdrasilSerializable;
import org.jetbrains.annotations.NotNull;

import java.util.*;
Expand All @@ -13,7 +12,7 @@
*/
@Container.ContainerType(Object.class)
public class SkriptQueue extends LinkedList<@NotNull Object>
implements Deque<Object>, Queue<Object>, YggdrasilSerializable, AnyAmount, Container<Object> {
implements Deque<Object>, Queue<Object>, AnyAmount, Container<Object> {

@Override
public boolean add(Object element) {
Expand Down Expand Up @@ -101,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
12 changes: 11 additions & 1 deletion src/test/skript/tests/syntaxes/expressions/ExprName.sk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ test "name of item":
set the name of {_thing} to "blob"
assert name of {_thing} is "blob" with "item name didn't change"

test "name of block":
set {_data} to blockdata of block at event-location
set block at event-location to a chest
assert name of block at event-location is not set with "The block shouldn't have a name yet"
set name of block at event-location to "Mr Chesty"
assert name of block at event-location = "Mr Chesty" with "The block should have a name now"
reset name of block at event-location
assert name of block at event-location is not set with "The block should no longer have a name"
set block at event-location to {_data}

using script reflection

test "config name (new)":
Expand All @@ -53,7 +63,7 @@ test "node name (new)":
assert name of {_node} is "test ""name of world""" with "first node name was wrong"

set {_node} to the current script
set {_node} to the 4th element of nodes of {_node} # Obviously, this changes if this file changes
set {_node} to the 5th element of nodes of {_node} # Obviously, this changes if this file changes
assert name of {_node} is "using script reflection" with "4th node name was wrong"

# root node
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 2f2f7fc

Please sign in to comment.