From 5062ec83ba3224bb9ae984c917ae3c58071e2de9 Mon Sep 17 00:00:00 2001 From: harshasiddartha Date: Sat, 1 Nov 2025 01:07:40 +0530 Subject: [PATCH 1/4] Add single-argument vector function overload Implements vector(n) = vector(n, n, n) as requested in issue #8265. This adds a convenient overload to the vector function that accepts a single number argument and creates a vector with all components equal to that value. This is useful for developers who require all-n vectors, such as for display scale. Changes: - Added single-argument vector overload to DefaultFunctions.java - Added comprehensive tests to verify the functionality - Updated documentation with examples Fixes #8265 --- .../njol/skript/classes/data/DefaultFunctions.java | 10 ++++++++++ .../tests/syntaxes/expressions/ExprVectorFromXYZ.sk | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java index b05fceefd81..afdcaea37af 100644 --- a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java +++ b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java @@ -492,6 +492,16 @@ public Date[] executeSimple(Object[][] params) { args.get("z").doubleValue() ))); + Functions.register(DefaultFunction.builder(skript, "vector", Vector.class) + .description("Creates a new vector with all components equal to the given value. Equivalent to vector(n, n, n).") + .examples("vector(5) # same as vector(5, 5, 5)") + .since("2.13") + .parameter("n", Number.class) + .build(args -> { + double value = args.get("n").doubleValue(); + return new Vector(value, value, value); + })); + Functions.registerFunction(new SimpleJavaFunction("calcExperience", new Parameter[] { new Parameter<>("level", DefaultClasses.LONG, true, null) }, DefaultClasses.LONG, true) { diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk index de6b7bfeaf0..ea0203b2d10 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk @@ -9,3 +9,16 @@ test "vector from xyz": set {_random} to a random vector set {_vector} to a new vector from x component of {_random}, y component of {_random}, z component of {_random} assert {_vector} is {_random} with "random vector to created component equality failed (expected %{_random}%, got %{_vector}%)" + +test "vector single argument": + assert vector(5) is vector(5, 5, 5) with "single-argument vector(5) failed" + assert vector(0) is vector(0, 0, 0) with "single-argument vector(0) failed" + assert vector(-10) is vector(-10, -10, -10) with "single-argument vector(-10) failed" + assert vector(3.14) is vector(3.14, 3.14, 3.14) with "single-argument vector(3.14) failed" + loop 60 times: + set {_n} to a random number between -100 and 100 + set {_vector} to vector({_n}) + assert {_vector} is vector({_n}, {_n}, {_n}) with "randomly-created single-argument vector equality failed (expected %vector({_n}, {_n}, {_n})%, got %{_vector}%)" + assert the x component of {_vector} is {_n} with "single-argument vector x component failed" + assert the y component of {_vector} is {_n} with "single-argument vector y component failed" + assert the z component of {_vector} is {_n} with "single-argument vector z component failed" From 6e396b0905369445b078d5fd3cb0dbdb5f8bb155 Mon Sep 17 00:00:00 2001 From: harshasiddartha Date: Sat, 1 Nov 2025 02:51:48 +0530 Subject: [PATCH 2/4] Update version to 2.13-pre1 per reviewer feedback --- src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java index afdcaea37af..fad5281f010 100644 --- a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java +++ b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java @@ -495,7 +495,7 @@ public Date[] executeSimple(Object[][] params) { Functions.register(DefaultFunction.builder(skript, "vector", Vector.class) .description("Creates a new vector with all components equal to the given value. Equivalent to vector(n, n, n).") .examples("vector(5) # same as vector(5, 5, 5)") - .since("2.13") + .since("2.13-pre1") .parameter("n", Number.class) .build(args -> { double value = args.get("n").doubleValue(); From a9089e8024396911e7a5a79f4aa006b62db8c190 Mon Sep 17 00:00:00 2001 From: harshasiddartha Date: Sat, 1 Nov 2025 02:53:19 +0530 Subject: [PATCH 3/4] Update version to INSERT VERSION per reviewer suggestion --- src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java index fad5281f010..2f0242d833c 100644 --- a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java +++ b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java @@ -495,7 +495,7 @@ public Date[] executeSimple(Object[][] params) { Functions.register(DefaultFunction.builder(skript, "vector", Vector.class) .description("Creates a new vector with all components equal to the given value. Equivalent to vector(n, n, n).") .examples("vector(5) # same as vector(5, 5, 5)") - .since("2.13-pre1") + .since("INSERT VERSION") .parameter("n", Number.class) .build(args -> { double value = args.get("n").doubleValue(); From bf926634c0122a1a47afd3d760a310db191ccfc1 Mon Sep 17 00:00:00 2001 From: harshasiddartha Date: Sat, 1 Nov 2025 14:26:54 +0530 Subject: [PATCH 4/4] Fix function overload registration to support multiple signatures with same name The Namespace.addSignature method doesn't support overloads, so we need to check if a signature with the same name already exists before adding. This allows function overloads to work correctly while avoiding the 'function name already used' exception. --- src/main/java/ch/njol/skript/lang/function/Functions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/lang/function/Functions.java b/src/main/java/ch/njol/skript/lang/function/Functions.java index fbaefbe361a..7b703c305eb 100644 --- a/src/main/java/ch/njol/skript/lang/function/Functions.java +++ b/src/main/java/ch/njol/skript/lang/function/Functions.java @@ -68,7 +68,9 @@ public static DefaultFunction register(DefaultFunction function) { if (!name.matches(functionNamePattern)) throw new SkriptAPIException("Invalid function name '%s'".formatted(name)); - javaNamespace.addSignature((Signature) function.signature()); + if (javaNamespace.getSignature(name) == null) { + javaNamespace.addSignature((Signature) function.signature()); + } javaNamespace.addFunction((Function) function); globalFunctions.put(function.name(), javaNamespace);