Skip to content
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

Added the ability to change the text: Click to Unlock. As well as level and cost. #3977

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* It uses an {@link Inventory} to display {@link SlimefunGuide} contents.
*
* @author TheBusyBiscuit
* @author Svdermant
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
*
* @see SlimefunGuide
* @see SlimefunGuideImplementation
Expand Down Expand Up @@ -289,7 +290,7 @@ private void displaySlimefunItem(ChestMenu menu, ItemGroup itemGroup, Player p,
menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNoPermissionItem(), sfitem.getItemName(), message.toArray(new String[0])));
menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
} else if (isSurvivalMode() && research != null && !profile.hasUnlocked(research)) {
menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNotResearchedItem(), ChatColor.WHITE + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + Slimefun.getLocalization().getMessage(p, "guide.locked"), "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level(s)"));
menu.addItem(index, new CustomItemStack(ChestMenuUtils.getNotResearchedItem(), ChatColor.WHITE + ItemUtils.getItemName(sfitem.getItem()), "&4&l" + Slimefun.getLocalization().getMessage(p, "guide.locked"), "", "&a>" + Slimefun.getLocalization().getMessage(p, "guide.click-unlock"), "", "&7" + Slimefun.getLocalization().getMessage(p, "guide.Cost") + research.getCost() + Slimefun.getLocalization().getMessage(p, "guide.Level")));
Copy link
Contributor

Choose a reason for hiding this comment

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

the message key should be lowercase and use hyphens (-) to connect words.
And I don't think string concatenation is good here, better use placeholder.

Copy link
Author

@svdermant svdermant Sep 20, 2023

Choose a reason for hiding this comment

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

No i should not be Lowercase it works with this setup! :)
After all, I tested everything before the request!

Copy link
Contributor

Choose a reason for hiding this comment

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

The key should be lowercase, or it will break the naming convention.
Also, consider using a placeholder instead of concatenating 3 parts for the cost line.

Copy link
Author

@svdermant svdermant Sep 20, 2023

Choose a reason for hiding this comment

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

Hmmm did you mean "getMessage" or "getMessage(p, "guide.Cost")"
Should it be named getMessage(p, "guide.cost") ?

The red line shows the original.
Below is my slightly changed line

No placeholder was used there either. Do I know any placeholders that are marked with %? correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it should be "guide.cost" the whole key should be lowercase.

As for the formatting and placeholders look at the javadocs or some examples for the String#format method to find how it works.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think I need to read about it because the original code, i.e. the red line, doesn't use a placeholder either. It's actually a function query called research.getCost() its not a placeholder so please explain to me exactly what you mean by placeholders?

J3fftw1 marked this conversation as resolved.
Show resolved Hide resolved
menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
research.unlockFromGuide(this, p, profile, sfitem, itemGroup, page);
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/languages/en/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ placeholderapi:

guide:
locked: 'LOCKED'
click-unlock: You Must Unlock This!
Copy link
Contributor

Choose a reason for hiding this comment

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

Better keep the original Click to unlock

cost: 'Cost: '
level: ' Level(s)'
Copy link
Member

Choose a reason for hiding this comment

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

I personally dislike the space here, I think the language file should not include this space and move the space to the code. Not sure how other feels about this one. Any suggestion on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree

Copy link
Author

@svdermant svdermant Sep 20, 2023

Choose a reason for hiding this comment

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

without the spaces the languagewords is combined so in the lore stands without them cost1Level(s)
So i add the Spaces for it.

i dont know how to add spaces in the code by "&7" + Slimefun.getLocalization().getMessage(p, "guide.cost") + research.getCost() + Slimefun.getLocalization().getMessage(p, "guide.level"))) in line 292 at SurvivalSlimefunGuide.java

so i add spaces in the message key to solve this. Even if it's probably wrong.
I'm still pretty new.

Copy link
Author

Choose a reason for hiding this comment

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

on my local machine i removed for testing the spaces in the message keywords... the result is watching the picture.
2023-09-20_17 27 26

To solve this i add spaces ...

Or for better understand how can i add spaces in the code add line 293 at SurvivalSlimefunGuide.java

work-in-progress: 'This feature is not fully finished yet!'

locked-itemgroup:
Expand Down