Skip to content
Open
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
16 changes: 14 additions & 2 deletions src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import ch.njol.skript.util.Timespan.TimePeriod;
import ch.njol.util.Kleenean;
import ch.njol.util.Math2;
import org.bukkit.Bukkit;
import org.bukkit.WorldBorder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@Name("Expand/Shrink World Border")
@Description({
"Expand or shrink the size of a world border.",
Expand Down Expand Up @@ -80,14 +83,23 @@ protected void execute(Event event) {
if (to) {
input = Math2.fit(1, input, MAX_WORLDBORDER_SIZE);
for (WorldBorder worldBorder : worldBorders)
worldBorder.setSize(input, speed);
if (Objects.equals(Bukkit.getBukkitVersion().split("-")[0], "1.21.11")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad practice for version checking, you should use the Skript#isRunningMinecraft method.
Also since you’re using it quite often, you should cache it statically at the top.

worldBorder.changeSize(input, speed);
} else {
worldBorder.setSize(input, speed);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random extra space

Suggested change

}
} else {
if (shrink)
input = -input;
for (WorldBorder worldBorder : worldBorders) {
double size = worldBorder.getSize();
size = Math2.fit(1, size + input, MAX_WORLDBORDER_SIZE);
worldBorder.setSize(size, speed);
if (Objects.equals(Bukkit.getBukkitVersion().split("-")[0], "1.21.11")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save as above

worldBorder.changeSize(size, speed);
} else {
worldBorder.setSize(size, speed);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@Name("World Border")
@Description({
"Get the border of a world or a player.",
Expand Down Expand Up @@ -64,7 +67,12 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
worldBorder.setDamageAmount(to.getDamageAmount());
worldBorder.setDamageBuffer(to.getDamageBuffer());
worldBorder.setWarningDistance(to.getWarningDistance());
worldBorder.setWarningTime(to.getWarningTime());
if (Objects.equals(Bukkit.getBukkitVersion().split("-")[0], "1.21.11")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above with version

worldBorder.setWarningTimeTicks(to.getWarningTimeTicks());
} else {
worldBorder.setWarningTime(to.getWarningTime());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random extra space

Suggested change

}
} else if (object instanceof Player player) {
player.setWorldBorder(to);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import ch.njol.skript.util.Timespan.TimePeriod;
import ch.njol.util.Math2;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.Bukkit;
import org.bukkit.WorldBorder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@Name("Warning Time of World Border")
@Description("The warning time of a world border. If the border is shrinking, the player's screen will be tinted red once the border will catch the player within this time period.")
@Example("set world border warning time of {_worldborder} to 1 second")
Expand All @@ -27,7 +30,7 @@ public class ExprWorldBorderWarningTime extends SimplePropertyExpression<WorldBo

@Override
public @Nullable Timespan convert(WorldBorder worldBorder) {
return new Timespan(TimePeriod.SECOND, worldBorder.getWarningTime());
return new Timespan(TimePeriod.SECOND, worldBorder.getWarningTimeTicks());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this version safe?

}

@Override
Expand All @@ -42,10 +45,13 @@ public class ExprWorldBorderWarningTime extends SimplePropertyExpression<WorldBo
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
long input = delta == null ? 15 : (((Timespan) delta[0]).getAs(TimePeriod.SECOND));
for (WorldBorder worldBorder : getExpr().getArray(event)) {
long warnTime = Objects.equals(Bukkit.getBukkitVersion().split("-")[0], "1.21.11")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above about version checking

? worldBorder.getWarningTimeTicks()
: worldBorder.getWarningTime();
long warningTime = switch (mode) {
case SET, RESET -> input;
case ADD -> Math2.addClamped(worldBorder.getWarningTime(), input);
case REMOVE -> Math2.addClamped(worldBorder.getWarningTime(), -input);
case ADD -> Math2.addClamped(warnTime, input);
case REMOVE -> Math2.addClamped(warnTime, -input);
default -> throw new IllegalStateException();
};
setWarningTime(worldBorder, warningTime);
Expand All @@ -57,7 +63,13 @@ private static void setWarningTime(WorldBorder worldBorder, long inputTime) {
long time = Math2.multiplyClamped(inputTime, 20);
// fit and convert back to seconds
int warningTime = ((int) Math2.fit(0, time, Integer.MAX_VALUE)) / 20;
worldBorder.setWarningTime(warningTime);
if (Objects.equals(Bukkit.getBukkitVersion().split("-")[0], "1.21.11")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above with version checking

worldBorder.setWarningTimeTicks(warningTime);
} else {
worldBorder.setWarningTime(warningTime);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random extra space

Suggested change

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another random extra space

Suggested change

}

@Override
Expand Down