-
-
Notifications
You must be signed in to change notification settings - Fork 428
Quick fix to change from WarningTime to WarningTimeTicks and changed … #8504
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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.", | ||||
|
|
@@ -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")) { | ||||
| worldBorder.changeSize(input, speed); | ||||
| } else { | ||||
| worldBorder.setSize(input, speed); | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save as above |
||||
| worldBorder.changeSize(size, speed); | ||||
| } else { | ||||
| worldBorder.setSize(size, speed); | ||||
| } | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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.", | ||||
|
|
@@ -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")) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||
| } | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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") | ||||
|
|
@@ -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()); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this version safe? |
||||
| } | ||||
|
|
||||
| @Override | ||||
|
|
@@ -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") | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||
|
|
@@ -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")) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. random extra space
Suggested change
|
||||
| } | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another random extra space
Suggested change
|
||||
| } | ||||
|
|
||||
| @Override | ||||
|
|
||||
There was a problem hiding this comment.
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#isRunningMinecraftmethod.Also since you’re using it quite often, you should cache it statically at the top.