Skip to content

Commit

Permalink
Merge branch 'dev/patch' into fix/null-enum-lang-names
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus authored Feb 1, 2024
2 parents 08e987f + 555c76b commit 96775e0
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/java-17-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java-8-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/junit-17-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/junit-8-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
with:
submodules: recursive
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,15 @@ public void onPluginDisable(PluginDisableEvent event) {
try {
// Spigot removed the mapping for this method in 1.18, so its back to obfuscated method
// 1.19 mapping is u and 1.18 is v
String isRunningMethod = Skript.isRunningMinecraft(1, 19) ? "u" : Skript.isRunningMinecraft(1, 18) ? "v" :"isRunning";
String isRunningMethod = "isRunning";

if (Skript.isRunningMinecraft(1, 20)) {
isRunningMethod = "v";
} else if (Skript.isRunningMinecraft(1, 19)) {
isRunningMethod = "u";
} else if (Skript.isRunningMinecraft(1, 18)) {
isRunningMethod = "v";
}
IS_RUNNING = MC_SERVER.getClass().getMethod(isRunningMethod);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class ExprLocationFromVector extends SimpleExpression<Location> {

static {
Skript.registerExpression(ExprLocationFromVector.class, Location.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprLocationFromVector.class, Location.class, ExpressionType.COMBINED,
"%vector% to location in %world%",
"location (from|of) %vector% in %world%",
"%vector% [to location] in %world% with yaw %number% and pitch %number%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class ExprLocationVectorOffset extends SimpleExpression<Location> {

static {
Skript.registerExpression(ExprLocationVectorOffset.class, Location.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprLocationVectorOffset.class, Location.class, ExpressionType.COMBINED,
"%location% offset by [[the] vectors] %vectors%",
"%location%[ ]~[~][ ]%vectors%");
}
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/ch/njol/skript/expressions/ExprScripts.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
import ch.njol.util.Kleenean;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.bukkit.event.Event;

Expand All @@ -54,12 +57,12 @@ public class ExprScripts extends SimpleExpression<String> {

static {
Skript.registerExpression(ExprScripts.class, String.class, ExpressionType.SIMPLE,
"[all [of the]] scripts [(1:without ([subdirectory] paths|parents))]",
"[all [of the]] (enabled|loaded) scripts [(1:without ([subdirectory] paths|parents))]",
"[all [of the]] (disabled|unloaded) scripts [(1:without ([subdirectory] paths|parents))]");
"[all [of the]|the] scripts [1:without ([subdirectory] paths|parents)]",
"[all [of the]|the] (enabled|loaded) scripts [1:without ([subdirectory] paths|parents)]",
"[all [of the]|the] (disabled|unloaded) scripts [1:without ([subdirectory] paths|parents)]");
}

private static final String SCRIPTS_PATH = new File(Skript.getInstance().getDataFolder(), Skript.SCRIPTSFOLDER).getPath() + File.separator;
private static final Path SCRIPTS_PATH = Skript.getInstance().getScriptsFolder().getAbsoluteFile().toPath();

private boolean includeEnabled;
private boolean includeDisabled;
Expand All @@ -75,20 +78,27 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
protected String[] get(Event event) {
List<File> scripts = new ArrayList<>();
List<Path> scripts = new ArrayList<>();
if (includeEnabled) {
for (Script script : ScriptLoader.getLoadedScripts())
scripts.add(script.getConfig().getFile());
scripts.add(script.getConfig().getPath());
}
if (includeDisabled)
scripts.addAll(ScriptLoader.getDisabledScripts());
return formatFiles(scripts);
scripts.addAll(ScriptLoader.getDisabledScripts()
.stream()
.map(File::toPath)
.collect(Collectors.toList()));
return formatPaths(scripts);
}

@SuppressWarnings("null")
private String[] formatFiles(List<File> files) {
return files.stream()
.map(f -> noPaths ? f.getName() : f.getPath().replaceFirst(Pattern.quote(SCRIPTS_PATH), ""))
private String[] formatPaths(List<Path> paths) {
return paths.stream()
.map(path -> {
if (noPaths)
return path.getFileName();
return SCRIPTS_PATH.relativize(path.toAbsolutePath()).toString();
})
.toArray(String[]::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class ExprVectorAngleBetween extends SimpleExpression<Number> {

static {
Skript.registerExpression(ExprVectorAngleBetween.class, Number.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorAngleBetween.class, Number.class, ExpressionType.COMBINED,
"[the] angle between [[the] vectors] %vector% and %vector%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class ExprVectorBetweenLocations extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorBetweenLocations.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorBetweenLocations.class, Vector.class, ExpressionType.COMBINED,
"[the] vector (from|between) %location% (to|and) %location%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class ExprVectorCrossProduct extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorCrossProduct.class, Vector.class, ExpressionType.SIMPLE, "%vector% cross %vector%");
Skript.registerExpression(ExprVectorCrossProduct.class, Vector.class, ExpressionType.COMBINED, "%vector% cross %vector%");
}

@SuppressWarnings("null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class ExprVectorCylindrical extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorCylindrical.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorCylindrical.class, Vector.class, ExpressionType.COMBINED,
"[a] [new] cylindrical vector [(from|with)] [radius] %number%, [yaw] %number%(,| and) [height] %number%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class ExprVectorDotProduct extends SimpleExpression<Number> {

static {
Skript.registerExpression(ExprVectorDotProduct.class, Number.class, ExpressionType.SIMPLE, "%vector% dot %vector%");
Skript.registerExpression(ExprVectorDotProduct.class, Number.class, ExpressionType.COMBINED, "%vector% dot %vector%");
}

@SuppressWarnings("null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
public class ExprVectorFromDirection extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorFromDirection.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorFromDirection.class, Vector.class, ExpressionType.PROPERTY,
"vector[s] [from] %directions%",
"%directions% vector[s]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class ExprVectorFromXYZ extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorFromXYZ.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorFromXYZ.class, Vector.class, ExpressionType.COMBINED,
"[a] [new] vector [(from|at|to)] %number%,[ ]%number%(,[ ]| and )%number%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class ExprVectorFromYawAndPitch extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorFromYawAndPitch.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorFromYawAndPitch.class, Vector.class, ExpressionType.COMBINED,
"[a] [new] vector (from|with) yaw %number% and pitch %number%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class ExprVectorNormalize extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorNormalize.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorNormalize.class, Vector.class, ExpressionType.COMBINED,
"normalize[d] %vector%",
"%vector% normalized");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class ExprVectorOfLocation extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorOfLocation.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorOfLocation.class, Vector.class, ExpressionType.PROPERTY,
"[the] vector (of|from|to) %location%",
"%location%'s vector");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class ExprVectorSpherical extends SimpleExpression<Vector> {

static {
Skript.registerExpression(ExprVectorSpherical.class, Vector.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprVectorSpherical.class, Vector.class, ExpressionType.COMBINED,
"[new] spherical vector [(from|with)] [radius] %number%, [yaw] %number%(,| and) [pitch] %number%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class StructFunction extends Structure {
public static final Priority PRIORITY = new Priority(400);

private static final Pattern SIGNATURE_PATTERN =
Pattern.compile("(?:local )?function (" + Functions.functionNamePattern + ")\\((.*)\\)(?:\\s*(?:::| returns )\\s*(.+))?");
Pattern.compile("^(?:local )?function (" + Functions.functionNamePattern + ")\\((.*?)\\)(?:\\s*(?:::| returns )\\s*(.+))?$");
private static final AtomicBoolean VALIDATE_FUNCTIONS = new AtomicBoolean();

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test "vector from expressions conflict":
set {_x} to 1
set {_y} to 2
set {_z} to -3
set {_v} to vector from {_x}, {_y}, {_z}
set {_v2} to vector({_x}, {_y}, {_z})
assert {_v} is {_v2} with "Vector from not generating correct vector. Expected %{_v2}%, got %{_v}%"

0 comments on commit 96775e0

Please sign in to comment.