-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
ExprLore - Cleanup and Changes #7743
base: dev/feature
Are you sure you want to change the base?
ExprLore - Cleanup and Changes #7743
Conversation
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.
while i agree with the changes made, i think this is probably too much of a breaking change to be worth it with no syntax change, since items are used everywhere in skript. i'd be okay with locking the new behaviour behind an extra syntax, so the new behaviour would be applied with remove all "s" from >all< lore of item
for example.
there is precedent for locking better behaviour behind syntax, e.g. #6930. wdyt?
Efy, Efy, our non responsive Efy, I truly hope I did not read you saying remove acting like replace was "better behaviour", remove is by no means replace. This is truly disappointing some of the most disappointment I've felt since the day of my birth. Your suggestion for adding The little effort people need to do for supporting replacing from remove is overly easy and simple. As I've said users only need to change Old behavior broke current behavior conventions, nothing else in skript new or old (not confirmed) did behavior like this.
I'm confident that most people did not know you can add onto a specific line of lore since even I didn't until I made this PR so for 7-8 years I've never known this. I've also never seen it used in help channels, but that could also be me entirely missing them. I won't say it's amazing to have breaking changes, but there's a time when they are needed, I believe this is one of those times where the team/people shouldn't be dragging their feet in making a decision, #7712 is a time where taking a step back and deciding is fair and likely a good call. Lore of an item is a list, it's not a single lined string where replace should be used. Skript needs to follow a convention in handling changers and a list is not a single entry it's multiple. using As a further point, when skript eventually drops spigot and swaps to paper, the team will likely also have to convert to components later down the line. Converting components to string and back into a component will cause data loss depending on how they were made. You the team will likely have to make the decision I'm doing here eventually I believe now is better than never so when you eventually go through with this you don't have to rewrite the whole class.. |
In my opinion, this seems like something that should start as a discussion. I think we are getting ahead of ourselves by making a PR right now. |
I believe the PR being made, regardless of it's status of being accepted or not, is beneficial. It helps all to know what changes that should be considered and be a point of reference. |
the exact syntax does not matter, as long as you are able to differentiate it from the old way of removing.
this is still a change users need to do. they may need to replace hundreds of these occurrences across years of scripts, which is why a non-breaking change is, in my opinion, the only acceptable solution here.
the second option here is literally exactly what the point of using
i highly doubt components are going to be required as soon as they are implemented. we can't just break every chat string and item string. also, if we're trying to future-proof, why would we accept this pr if we're going to make it use components later on anyway?
finally, please refrain from rhetoric like this. how am i supposed to enjoy reviewing your prs if this is the level of respect i get for spending my voluntary free time on skript? if you do this again, i will not be reviewing your prs anymore. we should all respect each other as volunteers. |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
Good work so far. Although breaking, I think these changes are for the better. I am undecided on the ADD
/REMOVE
changer support for individual lines. I think it can help shorten the lines, though I do agree it is a bit odd for Skript (compared to other syntax). I will ask around to gather some other opinions.
// The maximum amount of lore an item can have is 256 | ||
// this change was made in 1.21.5 | ||
// source: https://minecraft.wiki/w/Data_component_format#lore | ||
modifiedLore = modifiedLore.stream().limit(256).toList(); |
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.
Is there an error if too much lore is passed?
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.
I'm honestly not sure, I didn't test it without the limitation as I just went off previous behavior. I'll keep a note for this to test it and see if we can remove it.
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.
Yep, I was thinking if we can remove it that would be good. If not, this is fine as-is.
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.
Didn't feel like loading a server to quickly test lore limit, it appears we're safer adding this paper's CraftMetaItem will throw an exception if invalid amount of lore is provided
While I was here went and checked it doesn't seem like there was a previous lore limit prior to 1.21.5 internally however I don't want to take the chance there to remove it, so I believe we're safer keeping this implemented as is, I could maybe implement a static field for max lore instead of splitting it as I did here
continue; | ||
} | ||
addLore.add(line); | ||
case SET, DELETE -> modifiedLore = (delta != null) ? List.of((String[]) delta) : null; |
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.
Casting delta is not guaranteed to be safe unfortunately, so you may need a different method of accomplishing this
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.
Do you have any suggestions for this? SInce delta can only ever be string unless someone does an unsafe call manually through new ExprClass().change()
or Changer#change()
. The only other way I could think of going through is
List<String> providedStrings = new ArrayList<>();
if (delta != null) {
for (Object object : delta) {
if (!(object instanceof String stringDelta)
continue;
providedStrings.add(stringDelta);
}
} else {
providedStrings = null;
}
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.
Yes what you did is safer — loop through the array and check the looped element
case REMOVE, REMOVE_ALL -> { | ||
boolean isAll = mode == ChangeMode.REMOVE_ALL; | ||
if (isAll) { | ||
//noinspection DataFlowIssue |
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.
What is the warning you're getting here?
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.
I believe the issue there was to do with casting delta
Co-authored-by: Patrick Miller <[email protected]>
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.
lazy fix for test
Description
This PR aims to
rewritecleanup the ExprLore class as well as make a test file explicitly for itself.In addition to all the amazing changes below, I've added early support for 1.21.5's new lore cap, so long as their server is running 1.21.5 the lore will cap itself out at 256
Breaking changes
Yes, I know the team hates them (I don't), but the behaviors were just wrong, and I can't see a reason to deprecate it if nothing else in skript behaves like this. Please read the information below, before reviewing this PR, I don't want to cause too many repeated answers that is already answered below.
The changes here were done to help make skript better and more flexible, I'm well aware of skript's love to lock
event-item
from modifications, but this should change if the ability isn't overly harmful to the player's experience.Click for information about changer breaking changes
add
,remove
andremove all
changers have been fully reworked to work only on a list bases than a single string line bases.ADD
In the past
add "test" to line 1 of player's tool's lore
internally was just doingline 1 of lore + "test"
this made zero sense sinceadd
is not something you would expect for concatenation, now that skript has bothString + String
andconcat(String...)
additionallyjoin x with y
I believe it's best to fully strip out this behavior in favor of only accepting add inadd x to lore of y
REMOVE/REMOVE_ALL
Similar to
ADD
theREMOVE
andREMOVE_ALL
also had wonky behavior when used along side bothlore of x
andline x of lore of y
The remove method previously would convert a list like
"My", "String", "Coolio"
into"My\nString\nCoolio"
and use.replace()
and/or.replaceAll()
, this lead to lore not actually being removed but instead just becoming blank i.e.remove "String" from lore of {_item}
->"My\n\nCoolio"
->"My", "", "Coolio"
this has been changed to now act upon list removal making it explicitly only when doinglore of x
and is no longer an accepted change mode forline x of lore of y
I've fully stripped out the creation of blanks in lore besides when using
set line x of lore of y to "blank"
, outside of it's current lore size, I believe this behavior was well received and made sense on a user end of things. However remove will no longer create a blank line when used, meaning someone doingWould instead need to be
Click for information about the less strict
ChangerUtils#acceptsChange
As someone will eventually point out the internal code no longer runs
ChangerUtils.acceptsChange(item, ChangeMode.SET, ItemStack.class, ItemType.class)
any time someone does a change, this is now exclusive to whenitem.getTime()
is notEventValues.TIME_NOW
. this allows for people to now doset lore of event-item to "hahahha"
which was previously unsupported.From the testing I've done there was no reason for this to be done for
TIME_NOW
, these *should* be the existing items meaning changes made to them should still apply to 90% of event-items in skript.People doing
set lore of past event-item to ...
andset lore of future event-item to ...
will still be checked against theChangerUtils.acceptsChange
and correctly return when the new event-value changers are active. Below is a complete list of events I tested this in to showcase the utility in it as well as how much more it opens to the user base. While it is regrettable that events which don't support it will not error, there are far fewer of those than events that it works in.The events tested in these are events that had event-itemstack and event-itemtype on the Skripthub site, so new 2.11 events were not tested.
Tested events that worked
https://docs.skriptlang.org/events.html?search=#anvil_prepare
https://docs.skriptlang.org/events.html?search=#book_edit
https://docs.skriptlang.org/events.html?search=#book_sign
https://docs.skriptlang.org/events.html?search=#click
https://docs.skriptlang.org/events.html?search=#drop
https://docs.skriptlang.org/events.html?search=#elytra_boost
https://docs.skriptlang.org/events.html?search=#prepare_craft
https://docs.skriptlang.org/events.html?search=#enchant_prepare
https://docs.skriptlang.org/events.html?search=#enchant
https://docs.skriptlang.org/events.html?search=#riptide
https://docs.skriptlang.org/events.html?search=#stop_using_item
https://docs.skriptlang.org/events.html?search=#player_pickup_arrow
https://docs.skriptlang.org/events.html?search=#inventory_pickup
https://docs.skriptlang.org/events.html?search=#inventory_item_move
https://docs.skriptlang.org/events.html?search=#inventory_click
https://docs.skriptlang.org/events.html?search=#item_mend
https://docs.skriptlang.org/events.html?search=#item_damage
https://docs.skriptlang.org/events.html?search=#item_spawn
https://docs.skriptlang.org/events.html?search=#pick_up
https://docs.skriptlang.org/events.html?search=#spawn
Tested events that didn't work
https://docs.skriptlang.org/events.html?search=#craft
https://docs.skriptlang.org/events.html?search=#armor_change
https://docs.skriptlang.org/events.html?search=#dispense
https://docs.skriptlang.org/events.html?search=#entity_breed
https://docs.skriptlang.org/events.html?search=#item_merge
Niche Special cases
https://docs.skriptlang.org/events.html?search=#place - This works but causes items to become well infinite
https://docs.skriptlang.org/events.html?search=#inventory_drag - This works but I am labeling special as it's only for cursor slot when using event-item
NOTE: I am writing this with zero sleep, and if things aren't making sense please let me know so I can update the message.
Target Minecraft Versions: any
Requirements: none
Related Issues: #6245