mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Add locale message for learning animation option
Add helper function to get value of selected option in the survival guide
This commit is contained in:
parent
fd12521a0a
commit
e7ae14beaf
@ -34,8 +34,9 @@ public class LearningAnimationOption implements SlimefunGuideOption<Boolean> {
|
||||
if (SlimefunPlugin.getRegistry().isLearningAnimationDisabled()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
boolean enabled = getSelectedOption(p, guide).orElse(true);
|
||||
ItemStack item = new CustomItem(Material.PAPER, "&bLearning Animation: &" + (enabled ? "aYes" : "4No"), "", "&7You can now toggle whether you", "&7will see information about your pondering in chat", "&7upon researching an item.", "", "&7\u21E8 &eClick to " + (enabled ? "disable" : "enable") + " your learning animation");
|
||||
String enabled = getSelectedOption(p, guide).orElse(true) ? "enabled" : "disabled";
|
||||
ItemStack item = new CustomItem(Material.PAPER, SlimefunPlugin.getLocalization().getMessages(
|
||||
p, "guide.options.learning-animation." + enabled));
|
||||
return Optional.of(item);
|
||||
}
|
||||
}
|
||||
|
@ -233,21 +233,12 @@ public final class SlimefunGuideSettings {
|
||||
* in their {@link SlimefunGuide}.
|
||||
* If they enabled this setting, they will see fireworks when they unlock a {@link Research}.
|
||||
*
|
||||
* @param p
|
||||
* The {@link Player}
|
||||
* @param p The {@link Player}
|
||||
*
|
||||
* @return Whether this {@link Player} wants to see fireworks when unlocking a {@link Research}
|
||||
*/
|
||||
public static boolean hasFireworksEnabled(@Nonnull Player p) {
|
||||
for (SlimefunGuideOption<?> option : options) {
|
||||
if (option instanceof FireworksOption) {
|
||||
FireworksOption fireworks = (FireworksOption) option;
|
||||
ItemStack guide = SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE);
|
||||
return fireworks.getSelectedOption(p, guide).orElse(true);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return getOptionValue(p, FireworksOption.class, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,15 +251,30 @@ public final class SlimefunGuideSettings {
|
||||
* @return Whether this {@link Player} wants to info messages in chat when unlocking a {@link Research}
|
||||
*/
|
||||
public static boolean hasLearningAnimationEnabled(@Nonnull Player p) {
|
||||
return getOptionValue(p, LearningAnimationOption.class, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the value of a {@link SlimefunGuideOption} that the {@link Player}
|
||||
* has set in their {@link SlimefunGuide}
|
||||
*
|
||||
* @param p The {@link Player}
|
||||
* @param cls Class of the {@link SlimefunGuideOption} to get the value of
|
||||
* @param defaultValue Default value to return in case the option is not found at all or has no value set
|
||||
* @param <T> Type of the {@link SlimefunGuideOption} value
|
||||
* @param <OPTION> Type of the {@link SlimefunGuideOption}
|
||||
* @return The value of given {@link SlimefunGuideOption}
|
||||
*/
|
||||
private static <T, OPTION extends SlimefunGuideOption<T>> T getOptionValue(@Nonnull Player p, @Nonnull Class<OPTION> cls, T defaultValue) {
|
||||
for (SlimefunGuideOption<?> option : options) {
|
||||
if (option instanceof LearningAnimationOption) {
|
||||
LearningAnimationOption learningAnimation = (LearningAnimationOption) option;
|
||||
if (cls.isInstance(option)) {
|
||||
OPTION o = (OPTION) option;
|
||||
ItemStack guide = SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE);
|
||||
return learningAnimation.getSelectedOption(p, guide).orElse(true);
|
||||
return o.getSelectedOption(p, guide).orElse(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -91,6 +91,25 @@ guide:
|
||||
name: '&aIs something missing?'
|
||||
lore: 'Click to add your own translation'
|
||||
|
||||
options:
|
||||
learning-animation:
|
||||
enabled:
|
||||
- '&bLearning Animation: &aYes'
|
||||
- ''
|
||||
- '&7You can now toggle whether you'
|
||||
- '&7will see information about your pondering in chat'
|
||||
- '&7upon researching an item.'
|
||||
- ''
|
||||
- '&7\u21E8 &eClick to disable your learning animation'
|
||||
disabled:
|
||||
- '&bLearning Animation: &4No'
|
||||
- ''
|
||||
- '&7You can now toggle whether you'
|
||||
- '&7will see information about your pondering in chat'
|
||||
- '&7upon researching an item.'
|
||||
- ''
|
||||
- '&7\\u21E8 &eClick to enable your learning animation'
|
||||
|
||||
title:
|
||||
main: 'Slimefun Guide'
|
||||
settings: 'Settings & Info'
|
||||
|
Loading…
Reference in New Issue
Block a user