Skip to content

Commit fd66446

Browse files
committed
Add array size check
1 parent 5c5e140 commit fd66446

4 files changed

Lines changed: 34 additions & 20 deletions

File tree

src/main/java/org/skriptlang/skript/bukkit/functions/BukkitFunctions.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
import ch.njol.skript.Skript;
44
import ch.njol.skript.lang.function.Functions;
55
import ch.njol.skript.util.ColorRGB;
6-
import ch.njol.skript.util.Date;
76
import ch.njol.skript.util.Utils;
8-
import ch.njol.util.Math2;
97
import org.bukkit.Bukkit;
108
import org.bukkit.Location;
119
import org.bukkit.OfflinePlayer;
1210
import org.bukkit.World;
1311
import org.bukkit.entity.Player;
14-
import org.bukkit.util.Vector;
1512
import org.skriptlang.skript.addon.SkriptAddon;
1613
import org.skriptlang.skript.common.function.DefaultFunction;
1714
import org.skriptlang.skript.common.function.Parameter.Modifier;
1815

19-
import java.util.Calendar;
2016
import java.util.UUID;
2117

2218
public class BukkitFunctions {
@@ -88,9 +84,9 @@ set block at location({_x}, {_y}, {_z}, {_w}) to stone
8884
long exp;
8985
if (level <= 0) {
9086
exp = 0;
91-
} else if (level >= 1 && level <= 15) {
87+
} else if (level <= 15) {
9288
exp = level * level + 6 * level;
93-
} else if (level >= 16 && level <= 30) { // Truncating decimal parts probably works
89+
} else if (level <= 30) { // Truncating decimal parts probably works
9490
exp = (int) (2.5 * level * level - 40.5 * level + 360);
9591
} else { // Half experience points do not exist, anyway
9692
exp = (int) (4.5 * level * level - 162.5 * level + 2220);
@@ -181,8 +177,6 @@ set block at location({_x}, {_y}, {_z}, {_w}) to stone
181177
result = Bukkit.getOfflinePlayer(uuid); // doesn't do lookups
182178
} else if (hasIfCached && !args.getOrDefault("allowLookups", true)) {
183179
result = Bukkit.getOfflinePlayerIfCached(name);
184-
if (result == null)
185-
return null;
186180
} else {
187181
result = Bukkit.getOfflinePlayer(name);
188182
}

src/main/java/org/skriptlang/skript/common/elements/functions/MathFunctions.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ private static String str(double n) {
225225
.parameter("ns", Number[].class)
226226
.build(args -> {
227227
Number[] ns = args.get("ns");
228+
if (ns.length == 0)
229+
return 0;
230+
228231
double sum = ns[0].doubleValue();
229232
for (int i = 1; i < ns.length; i++)
230233
sum += ns[i].doubleValue();
@@ -238,6 +241,9 @@ private static String str(double n) {
238241
.parameter("ns", Number[].class)
239242
.build(args -> {
240243
Number[] ns = args.get("ns");
244+
if (ns.length == 0)
245+
return 0;
246+
241247
double product = ns[0].doubleValue();
242248
for (int i = 1; i < ns.length; i++)
243249
product *= ns[i].doubleValue();
@@ -251,6 +257,9 @@ private static String str(double n) {
251257
.parameter("ns", Number[].class)
252258
.build(args -> {
253259
Number[] ns = args.get("ns");
260+
if (ns.length == 0)
261+
return 0;
262+
254263
double max = ns[0].doubleValue();
255264
for (int i = 1; i < ns.length; i++) {
256265
double d = ns[i].doubleValue();
@@ -267,6 +276,9 @@ private static String str(double n) {
267276
.parameter("ns", Number[].class)
268277
.build(args -> {
269278
Number[] ns = args.get("ns");
279+
if (ns.length == 0)
280+
return 0;
281+
270282
double min = ns[0].doubleValue();
271283
for (int i = 1; i < ns.length; i++) {
272284
double d = ns[i].doubleValue();
@@ -310,7 +322,11 @@ public Class<?> getReturnType(Expression<?>... arguments) {
310322
double trueMax = Math.max(min, max);
311323
for (int i = 0; i < values.length; i++) {
312324
double value = values[i].doubleValue();
313-
clampedValues[i] = Math.clamp(value, trueMin, trueMax);
325+
if (!Double.isNaN(value) && !Double.isNaN(trueMin) && !Double.isNaN(trueMax)) {
326+
clampedValues[i] = Math.clamp(value, trueMin, trueMax);
327+
} else {
328+
clampedValues[i] = 0d;
329+
}
314330
}
315331
return clampedValues;
316332
}));

src/main/java/org/skriptlang/skript/common/elements/functions/StringFunctions.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ public class StringFunctions {
2828
"A hashtag '#' represents a digit, a comma ',' is used to separate numbers, and a period '.' is used for decimals. ",
2929
"Will return none if the format is invalid.",
3030
"For further reference, see this <a href=\"https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html\" target=\"_blank\">article</a>.")
31-
.examples(
32-
"command /balance:",
33-
"\taliases: bal",
34-
"\texecutable by: players",
35-
"\ttrigger:",
36-
"\t\tset {_money} to formatNumber({money::%sender's uuid%})",
37-
"\t\tsend \"Your balance: %{_money}%\" to sender")
31+
.examples("""
32+
command /balance:
33+
aliases: bal
34+
executable by: players
35+
trigger:
36+
set {_money} to formatNumber({money::%sender's uuid%})
37+
send "Your balance: %{_money}%" to sender
38+
""")
3839
.since("2.10")
3940
.parameter("number", Number.class)
4041
.parameter("format", String.class, Modifier.OPTIONAL)
@@ -71,9 +72,10 @@ public class StringFunctions {
7172

7273
Functions.register(DefaultFunction.builder(skript, "concat", String.class)
7374
.description("Joins the provided texts (and other things) into a single text.")
74-
.examples(
75-
"concat(\"hello \", \"there\") # hello there",
76-
"concat(\"foo \", 100, \" bar\") # foo 100 bar"
75+
.examples("""
76+
concat("hello ", "there") # hello there
77+
concat("foo ", 100, " bar") # foo 100 bar
78+
"""
7779
)
7880
.since("2.9.0")
7981
.parameter("texts", Object[].class)

src/main/java/org/skriptlang/skript/common/elements/functions/TimeFunctions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public class TimeFunctions {
1818
Functions.register(DefaultFunction.builder(skript, "date", Date.class)
1919
.description("Creates a date from a year, month, and day, and optionally also from hour, minute, second and millisecond.",
2020
"A time zone and DST offset can be specified as well (in minutes), if they are left out the server's time zone and DST offset are used (the created date will not retain this information).")
21-
.examples("date(2014, 10, 1) # 0:00, 1st October 2014", "date(1990, 3, 5, 14, 30) # 14:30, 5th May 1990", "date(1999, 12, 31, 23, 59, 59, 999, -3*60, 0) # almost year 2000 in parts of Brazil (-3 hours offset, no DST)")
21+
.examples("date(2014, 10, 1) # 0:00, 1st October 2014",
22+
"date(1990, 3, 5, 14, 30) # 14:30, 5th May 1990",
23+
"date(1999, 12, 31, 23, 59, 59, 999, -3*60, 0) # almost year 2000 in parts of Brazil (-3 hours offset, no DST)")
2224
.since("2.2")
2325
.parameter("year", Number.class)
2426
.parameter("month", Number.class)

0 commit comments

Comments
 (0)