-
-
Notifications
You must be signed in to change notification settings - Fork 413
Converting bases, color hex codes, and ranged function parameters #8314
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
Open
sovdeeth
wants to merge
8
commits into
dev/feature
Choose a base branch
from
feature/bases-colors-ranges
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
|
Test failure is due to odd interaction between runtime error and simplification |
Efnilite
requested changes
Dec 10, 2025
src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Outdated
Show resolved
Hide resolved
src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/common/expressions/ExprColorFromHexCode.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/common/expressions/ExprHexCode.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/common/function/DefaultFunctionImpl.java
Outdated
Show resolved
Hide resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
Feature request, an issue about something that could be improved, or a PR improving something.
feature
Pull request adding a new feature.
needs reviews
A PR that needs additional reviews
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
I sincerely apologize for shoving
threefour different PRs together, they just all seemed to build on each other. If one proves controversial, I'll spin it out to its own PR.Color hex codes: The driving force for this PR. @cheeezburga's color pr, #7246, has a useful 'hex code of color' expression, which I want to use to assist in formatting chat messages based on color objects. Since that pr seems to be stale, I'm pulling it over here. I also added a color from hex expression as an inverse relationship.
Converting bases: Since we're providing hex conversion to decimal implicitly in color conversion, we should support it fully. Currently, there's no easy way to convert between bases. Users have used
character x in "0123456789..."as a workaround, but it'd be nicer and easier to have it as a built-in function for many bases at once.Ranged function parameters: The base conversion methods in Java only allow bases between 2 and 36. I wanted more robust limits on the function parameter inputs, like parse errors if the input was a literal and out of range.
Fixes to runtime error catching/simplification errors: If a element tries to simplify but encounters a runtime error, it currently just prints that error and whatever output is used for the simplification, leading to subsequent calls not triggering the runtime. Plus the error catcher section wasn't actually suppressing errors, only storing copies while still printing them.
Solution
Color hex codes: 2 new expressions,
hex code of %colors%andcolour from hex code %strings%. Support for to/from hex strings was added to Color/ColorRGB.Converting bases: 2 new functions, toBase(value, base) and fromBase(value, base). These use Integer.parseInt() and toString() to convert between bases. the base parameter is ranged from 2 to 36.
Ranged function parameters: Adds a new Modifier, Modifier.RANGED. You can use Modifier.ranged(min, max) to set an inclusive range for a parameter with any Comparable type. If the inputs are literals, Skript will check them against the range and issue parse errors if they're outside:

The ranges are also shown in the docs:

Runtime errors: Spun simplification into a helper function, wrapped in a RuntimeErrorCatcher, and prints Skript.error() if it catches any. Actually removes all consumers in removeAllConsumers (whoops!).
Testing Completed
Added tests for color expressions and base functions.
Supporting Information
Completes: none
Related: none
AI assistance: none