Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply new line (%nr%) in item lore correctly #3636

Merged
merged 7 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package ch.njol.skript.expressions;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.bukkit.event.Event;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -62,10 +64,13 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean kleenean

@Override
protected ItemType[] get(Event e, ItemType[] source) {
String[] lore = this.lore.getArray(e);
List<String> lore = this.lore.stream(e)
.flatMap(l -> Arrays.stream(l.split("\n")))
.collect(Collectors.toList());

return get(source, item -> {
ItemMeta meta = item.getItemMeta();
meta.setLore(Arrays.asList(lore));
meta.setLore(lore);
item.setItemMeta(meta);
return item;
});
Expand Down
19 changes: 19 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprItemWithLore.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test "item with lore as one string without newline":
set {_i1} to 1 of stone with lore "first line"
assert the line 1 of lore of {_i1} is "first line" with "has correct first line"

test "item with lore as multiple string without newline":
set {_i2} to 1 of stone with lore "first line" and "second line"
assert the line 1 of lore of {_i2} is "first line" with "has correct first line"
assert the line 2 of lore of {_i2} is "second line" with "has correct second line"

test "item with lore as one string with newline":
set {_i3} to 1 of stone with lore "first line%nl%second line"
assert the line 1 of lore of {_i3} is "first line" with "has correct first line"
assert the line 2 of lore of {_i3} is "second line" with "has correct second line"

test "item with lore as multiple string with newline":
set {_i4} to 1 of stone with lore "first line%nl%second line" and "third line"
assert the line 1 of lore of {_i4} is "first line" with "has correct first line"
assert the line 2 of lore of {_i4} is "second line" with "has correct second line"
assert the line 3 of lore of {_i4} is "third line" with "has correct third line"