Skip to content

allow location to be parsed from an exact string#8773

Open
MrScopes wants to merge 5 commits into
SkriptLang:dev/featurefrom
MrScopes:parselocation
Open

allow location to be parsed from an exact string#8773
MrScopes wants to merge 5 commits into
SkriptLang:dev/featurefrom
MrScopes:parselocation

Conversation

@MrScopes

@MrScopes MrScopes commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Location strings cannot be parsed as a location, users would need to manually split the string themself then form the location that way.

Solution

Allow string to be parsed back into location if it matches the required format.
x: number, y: number, z: number, yaw: number, pitch: number [in 'world']

Testing Completed

on load:
    set {-loc} to location of spawn of world "world"
    broadcast "Location: %{-loc}%" # x: 0, y: 106, z: 0, yaw: 0, pitch: 0 in 'world'

    set {_parsed} to "%{-loc}%"
    broadcast "%{_parsed}.getClass()% - %{_parsed}%" # class java.lang.String - x: 0, y: 106, z: 0, yaw: 0, pitch: 0 in 'world'
    set {_parsed} to {_parsed} parsed as location
    broadcast "%{_parsed}.getClass()% - %{_parsed}%, %world of {_parsed}%" # class org.bukkit.Location - x: 0, y: 106, z: 0, yaw: 0, pitch: 0 in 'world', world

    set {_good} to "x: 1, y: 2, z: 3, yaw: 4, pitch: 5 in 'world'" parsed as location
    broadcast "%{_good}% - %world of {_good}%" # x: 1, y: 2, z: 3, yaw: 4, pitch: 5 in 'world' - world

    set {_decimals} to "x: 1.2542, y: -1.2, z: -250, yaw: -35.15, pitch: 1.35 in 'world'" parsed as location
    broadcast "%{_decimals}% - %world of {_decimals}%" # : 1.25, y: -1.2, z: -250, yaw: -35.15, pitch: 1.35 in 'world' - world

    set {_world doesnt exist} to "x: 1, y: 2, z: 3, yaw: 4, pitch: 5 in 'doesnt exist'" parsed as location
    broadcast "%{_world doesnt exist}% - %world of {_world doesnt exist}%" # x: 1, y: 2, z: 3, yaw: 4, pitch: 5 - <none>

    set {_no world} to "x: 1, y: 2, z: 3, yaw: 4, pitch: 5" parsed as location
    broadcast "%{_no world}% - %world of {_no world}%" # x: 1, y: 2, z: 3, yaw: 4, pitch: 5 - <none>

    set {_bad coordinate} to "x: bad coordinate, y: 2, z: 3, yaw: 4, pitch: 5 in 'world'" parsed as location
    broadcast "%{_bad coordinate}% - %world of {_bad coordinate}%" # <none> - <none>

    set {_bad format} to "x: 1 y: 2, z: 3, yaw: 4, pitch: 5 in 'world'" parsed as location
    broadcast "%{_bad format}% - %world of {_bad format}%" # <none> - <none>

    set {_bad numbers} to "x: 1.2.3, y: 2, z: 3, yaw: 4, pitch: 5 in 'world'" parsed as location
    broadcast "%{_bad numbers}% - %world of {_bad numbers}%" # <none> - <none>

Supporting Information

Just a proposal. Not sure if this has been discussed or why/why not it would be allowed or disallowed.


Completes: 8772
Related: none
AI assistance: CoPilot

@MrScopes
MrScopes requested a review from a team as a code owner July 13, 2026 17:49
@MrScopes
MrScopes requested review from Efnilite and TheMug06 and removed request for a team July 13, 2026 17:49
@MrScopes

Copy link
Copy Markdown
Contributor Author

@bluelhf

Comment thread src/main/java/org/skriptlang/skript/bukkit/types/LocationClassInfo.java Outdated
}

private static class LocationParser extends Parser<Location> {
private static final String NUMBER = "[-+]?\\d+(?:\\.\\d+)?";

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.

Don't use a regex matcher, split based on keywords and use the same parsers that are used for toString in the first place.

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.

Don't use a regex matcher, split based on keywords and use the same parsers that are used for toString in the first place.

which approach would you recommend?

substring at each
x:
y:
z:
...
manually handle world as a part of pitch

or, do the same thing but split at commas?
the issue is there's still some requirement to run different code to get the world since the format is
x: 0, y: 0, z: 0, yaw: 0, pitch: 0 in world 'world'
since in world is basically apart of pitch if I split at by commas
this is why I thought using regex instead was a no brainer

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.

Split at x: , , y: , , z: , , yaw: , , pitch: and in ' (the exact strings from toString); if the last of which is missing, then the world was null. Not using regex helps avoid bugs here, for example your current NUMBER regex is incorrect because it does not match NaN or Infinity (which are valid outputs from toString!)

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.

Pushed my most recent changes. is this what you meant?

Comment thread src/main/java/org/skriptlang/skript/bukkit/types/LocationClassInfo.java Outdated
@skriptlang-automation skriptlang-automation Bot added the needs reviews A PR that needs additional reviews label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs reviews A PR that needs additional reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants