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

ExprName - fix not being able to get/set name of block #7503

Merged
merged 1 commit into from
Jan 22, 2025
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 @@ -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
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
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
Loading