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 - combine elements and cleanup docs #7370

Merged
merged 3 commits into from
Jan 3, 2025
Merged
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
83 changes: 36 additions & 47 deletions src/main/java/ch/njol/skript/expressions/ExprName.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.function.DynamicFunctionReference;
import ch.njol.skript.lang.util.common.AnyNamed;
Expand Down Expand Up @@ -38,56 +39,40 @@
import org.skriptlang.skript.lang.script.Script;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Name("Name / Display Name / Tab List Name")
@Description({
"Represents the Minecraft account, display or tab list name of a player, or the custom name of an item, entity, "
+ "block, inventory, gamerule, world, script or function.",
"",
"<ul>",
"\t<li><strong>Players</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name:</strong> The Minecraft account name of the player. Can't be changed, but 'display name' can be changed.</li>",
"\t\t\t<li><strong>Display Name:</strong> The name of the player that is displayed in messages. " +
"This name can be changed freely and can include color codes, and is shared among all plugins (e.g. chat plugins will use the display name).</li>",
"\t\t</ul>",
"\t</li>",
"\t<li><strong>Entities</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name:</strong> The custom name of the entity. Can be changed. But for living entities, " +
"the players will have to target the entity to see its name tag. For non-living entities, the name will not be visible at all. To prevent this, use 'display name'.</li>",
"\t\t\t<li><strong>Display Name:</strong> The custom name of the entity. Can be changed, " +
"which will also enable <em>custom name visibility</em> of the entity so name tag of the entity will be visible always.</li>",
"\t\t</ul>",
"\t</li>",
"\t<li><strong>Items</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name and Display Name:</strong> The <em>custom</em> name of the item (not the Minecraft locale name). Can be changed.</li>",
"\t\t</ul>",
"\t</li>",
"\t<li><strong>Inventories</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name and Display Name:</strong> The name/title of the inventory. " +
"Changing name of an inventory means opening the same inventory with the same contents but with a different name to its current viewers.</li>",
"\t\t</ul>",
"\t</li>",
"\t<li><strong>Gamerules (1.13+)</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name:</strong> The name of the gamerule. Cannot be changed.</li>",
"\t\t</ul>",
"\t</li>",
"\t<li><strong>Worlds</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name:</strong> The name of the world. Cannot be changed.</li>",
"\t\t</ul>",
"\t</li>",
"\t<li><strong>Scripts</strong>",
"\t\t<ul>",
"\t\t\t<li><strong>Name:</strong> The name of a script, excluding its file extension.</li>",
"\t\t</ul>",
"\t</li>",
"</ul>"
"<strong>Players:</strong>",
"\t<strong>Name:</strong> The Minecraft account name of the player. Can't be changed, but 'display name' can be changed.",
"\t<strong>Display Name:</strong> The name of the player that is displayed in messages. " +
"This name can be changed freely and can include color codes, and is shared among all plugins (e.g. chat plugins will use the display name).",
"",
"<strong>Entities:</strong>",
"\t<strong>Name:</strong> The custom name of the entity. Can be changed. But for living entities, " +
"the players will have to target the entity to see its name tag. For non-living entities, the name will not be visible at all. To prevent this, use 'display name'.",
"\t<strong>Display Name:</strong> The custom name of the entity. Can be changed, " +
"which will also enable <em>custom name visibility</em> of the entity so name tag of the entity will be visible always.",
"",
"<strong>Items:</strong>",
"\t<strong>Name and Display Name:</strong> The <em>custom</em> name of the item (not the Minecraft locale name). Can be changed.",
"",
"<strong>Inventories:</strong>",
"\t<strong>Name and Display Name:</strong> The name/title of the inventory. " +
"Changing name of an inventory means opening the same inventory with the same contents but with a different name to its current viewers.",
"",
"<strong>Gamerules:</strong>",
"\t<strong>Name:</strong> The name of the gamerule. Cannot be changed.",
"",
"<strong>Worlds:</strong>",
"\t<strong>Name:</strong> The name of the world. Cannot be changed.",
"",
"<strong>Scripts:</strong>",
"\t<strong>Name:</strong> The name of a script, excluding its file extension."
})
@Examples({
"on join:",
Expand All @@ -107,9 +92,13 @@ public class ExprName extends SimplePropertyExpression<Object, String> {
if (Skript.classExists("net.kyori.adventure.text.Component") &&
Skript.methodExists(Bukkit.class, "createInventory", InventoryHolder.class, int.class, Component.class))
serializer = BungeeComponentSerializer.get();
register(ExprName.class, String.class, "(1:name[s])", "offlineplayers/entities/inventories/nameds");
register(ExprName.class, String.class, "(2:(display|nick|chat|custom)[ ]name[s])", "offlineplayers/entities/inventories/nameds");
register(ExprName.class, String.class, "(3:(player|tab)[ ]list name[s])", "players");

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("(player|tab)[ ]list name[s]", "players")));

Skript.registerExpression(ExprName.class, String.class, ExpressionType.COMBINED, patterns.toArray(new String[0]));
// we keep the entity input because we want to do something special with entities
}

Expand All @@ -123,7 +112,7 @@ public class ExprName extends SimplePropertyExpression<Object, String> {

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
this.mark = parseResult.mark;
this.mark = (matchedPattern / 2) + 1;
this.setExpr(exprs[0]);
this.scriptResolvedName = this.getParser().hasExperiment(Feature.SCRIPT_REFLECTION);
return true;
Expand Down
Loading