Skip to content

Add worldborders#7006

Merged
Efnilite merged 62 commits into
SkriptLang:dev/featurefrom
Phill310:feature/worldborder
Mar 20, 2025
Merged

Add worldborders#7006
Efnilite merged 62 commits into
SkriptLang:dev/featurefrom
Phill310:feature/worldborder

Conversation

@Phill310
Copy link
Copy Markdown
Contributor

@Phill310 Phill310 commented Aug 29, 2024

Description

Add worldborder syntax to Skript. Continuation of #5229
Player's worldborder is always virtual

Conditions:

  • updated IsWithin condition

Effects:

  • expand/shrink worldborder (maybe add grow/contract aliases)
    I don't like the way I am registering the syntax right now with the of and 's but I can't think of a different way

Events:

  • Worldborder bounds change
  • Worldborder bounds finish change
  • Worldborder center change

Expressions:

  • worldborder
  • worldborder center
  • worldborder damage amount
  • worldborder damage buffer
  • worldborder size
  • worldborder warning distance
  • worldborder warning time

Sections:

  • Create worldborder

Target Minecraft Versions: any
Requirements: Paper for worldborder events
Related Issues: #5178, #3848

Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorder.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorder.java
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorder.java
Comment thread src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderSize.java Outdated
Copy link
Copy Markdown
Contributor

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

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

TEST!

Comment thread src/main/java/ch/njol/skript/classes/data/BukkitClasses.java Outdated
Comment thread src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Comment thread src/main/java/ch/njol/skript/conditions/CondIsInsideWorldBorder.java Outdated
Comment thread src/main/java/ch/njol/skript/conditions/CondIsInsideWorldBorder.java Outdated
Comment thread src/main/java/ch/njol/skript/conditions/CondIsInsideWorldBorder.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderSize.java
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderSize.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderWarningDistance.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderWarningTime.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderWarningTime.java Outdated
@Fusezion
Copy link
Copy Markdown
Contributor

A lot of chez's stuff might of been repeated he beat me ;(

@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Aug 30, 2024
@Phill310 Phill310 marked this pull request as ready for review September 9, 2024 01:55
Comment thread src/test/skript/tests/syntaxes/effects/EffWorldborderExpand.sk Outdated
Copy link
Copy Markdown
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

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

just needs some formatting updates, mainly around annotations!

Comment thread src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Comment thread src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderSize.java Outdated
Comment thread src/main/java/ch/njol/skript/bukkitutil/BukkitUnsafe.java Outdated
Comment thread src/main/java/ch/njol/skript/aliases/Aliases.java Outdated
Comment thread src/main/java/ch/njol/skript/classes/data/BukkitClasses.java Outdated
Comment thread src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderWarningTime.java Outdated
import org.jetbrains.annotations.Nullable;

@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.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so if the player is outside the border it will be tinted red after one second? im not sure what this expression does

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its specifically when the worldborder is shrinking. If the player is outside the final worldborder (after the shrink), their screen will turn red x seconds before it reaches their current location

Comment thread src/test/skript/tests/syntaxes/effects/EffWorldborderExpand.sk Outdated
Comment thread src/test/skript/tests/syntaxes/effects/EffWorldborderExpand.sk
Copy link
Copy Markdown
Contributor

@Absolutionism Absolutionism left a comment

Choose a reason for hiding this comment

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

Just a few things

Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorder.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderCenter.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderDamageAmount.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderDamageBuffer.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderSize.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderDamageAmount.java Outdated
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderCenter.java Outdated
Location location = mode == ChangeMode.SET ? (Location) delta[0] : null;
for (WorldBorder worldBorder : getExpr().getArray(event)) {
switch (mode) {
case SET:
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.

Not a big deal, but maybe an enhanced switch?

Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorder.java
Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderCenter.java
Copy link
Copy Markdown
Contributor

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

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

Leaving a proper review to other people, but uhh thoughts on WorldBorder x AnySizedThing? size of worldborder, set size of worldborder to 10

Comment thread src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Comment thread src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java Outdated
Copy link
Copy Markdown
Contributor

@Absolutionism Absolutionism left a comment

Choose a reason for hiding this comment

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

Looking good

import org.bukkit.event.player.PlayerQuitEvent.QuitReason;
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason;
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.

I know you've had some trouble merging/updating your branch, so let's hope nothing got removed in the making.

Comment thread src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java Outdated
Comment thread src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java
Comment thread src/main/java/ch/njol/skript/expressions/ExprSecCreateWorldBorder.java Outdated
Comment on lines +54 to +61
if (((long) worldBorder.getWarningDistance() + input) > Integer.MAX_VALUE) {
worldBorder.setWarningDistance(Integer.MAX_VALUE);
} else if (((long) worldBorder.getWarningDistance() + input) < Integer.MIN_VALUE) {
worldBorder.setWarningDistance(Integer.MIN_VALUE);
} else {
worldBorder.setWarningDistance(Math.max(worldBorder.getWarningDistance() + input, 0));
}
break;
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.

Suggested change
if (((long) worldBorder.getWarningDistance() + input) > Integer.MAX_VALUE) {
worldBorder.setWarningDistance(Integer.MAX_VALUE);
} else if (((long) worldBorder.getWarningDistance() + input) < Integer.MIN_VALUE) {
worldBorder.setWarningDistance(Integer.MIN_VALUE);
} else {
worldBorder.setWarningDistance(Math.max(worldBorder.getWarningDistance() + input, 0));
}
break;
int current = worldBorder.getWarningDistance();
int value = Math2.fit(0, current + input, Integer.MAX_VALUE);
worldBorder.setWarningDistance(value)

Shouldnt be using MIN_VALUE because that's a negative, I dont think a world border should have a negative distance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The MIN_VALUE part is true but I did the rest of it to catch integer overflows during the addition / subtraction. It seems like the Math2.fit wouldn't help that unless I am misunderstanding the code

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.

Well one thing you should do, is in #acceptChange instead of returning Number.class you should do Integer.class in my opinion. As that in itself would exclude any nan and infinite values. As well as capping the provided number to Integer.MAX_VALUE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I dont think switching it to integer class fixed the integer overflow issues so I think it might leave it as is with the MIN_VALUE thing fixed

Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderWarningTime.java Outdated
Comment thread src/test/skript/tests/syntaxes/sections/ExprSecCreateWorldBorder.sk Outdated
@Phill310
Copy link
Copy Markdown
Contributor Author

Phill310 commented Mar 8, 2025

Leaving a proper review to other people, but uhh thoughts on WorldBorder x AnySizedThing? size of worldborder, set size of worldborder to 10

What do you mean? Is this some newer feature that I haven't seen yet / forgot about?

Copy link
Copy Markdown
Contributor

@Absolutionism Absolutionism left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Copy Markdown
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

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

looks good to me
i appreciate the very thorough tests

Comment thread src/main/java/ch/njol/skript/expressions/ExprWorldBorderCenter.java Outdated
@sovdeeth sovdeeth added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Mar 15, 2025
@Efnilite Efnilite requested a review from a team as a code owner March 20, 2025 13:25
@Efnilite Efnilite requested review from cheeezburga and erenkarakal and removed request for Fusezion March 20, 2025 13:25
@Efnilite Efnilite merged commit 1e43779 into SkriptLang:dev/feature Mar 20, 2025
@Phill310 Phill310 deleted the feature/worldborder branch March 26, 2025 00:28
erenkarakal pushed a commit to erenkarakal/Skript that referenced this pull request Nov 26, 2025
* Initial setup

* Fix imports

* Use pattern variables for instanceof

* Cleaner switch statements

* Specify paper version

* Use newer timespan method

* Require "world border" when editing a world border's attributes

* Move IsInsideWorldBorder to IsWithin condition

* Make variable name readable

* Clean up conditions

* Make radius/diameter optional

* Make damage have a minimum of 0

* Make warning distance have a minimum of 0

* Make damage buffer have a minimum of 0

* Make warning time have a minimum of 0

* Force the center location to stay inside the limits defined by WorldBorder#getMaxCenterCoordinate

* Tests!

* End files with a new line

* Apply suggestions from code review

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>

* Correct annotation placement

* Apply suggestions from code review

Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com>

* Phil's stuff.

* More of Phil's stuff.

* Whoops I imported again

* Apply suggestions from code review

Co-authored-by: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com>

* register properties as defaults

* Add docs

* Clean up toString

* Update tests

* Apply suggestions from code review

Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>

* Fix imports

* Remove duplicate event registration

* Update src/main/java/ch/njol/skript/expressions/ExprSecCreateWorldBorder.java

Co-authored-by: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com>

* Fix typo

* Validate inputs before setting the value

* Update src/main/java/ch/njol/skript/effects/EffWorldBorderExpand.java

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>

* Paper's getMaxSize method did not do what I expected

* Improve tests

* Add check for NaN

* Add check for NaN and infinite values

* Add check for NaN and overflow during integer math

* Apply suggestions from code review

Co-authored-by: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com>

* Move clamp outside loop

* Remove extra event-value registration

* Improve example for World Border Bounds Change Event

* Clean up imports

* Set the Warning Distance to 0 rather than MIN_VALUE

* Add more tests with large numbers

* Account for integer overflow issues

* Remove debug code

* Use signum to clean up conditions

---------

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Co-authored-by: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com>
Co-authored-by: Moderocky <admin@moderocky.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants