mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Add the option to disable learning animations server & client side
This commit is contained in:
parent
a4aebf7bcd
commit
227621906c
@ -69,6 +69,7 @@ public final class SlimefunRegistry {
|
||||
private boolean enableResearches;
|
||||
private boolean freeCreativeResearches;
|
||||
private boolean researchFireworks;
|
||||
private boolean disableLearningAnimation;
|
||||
private boolean logDuplicateBlockEntries;
|
||||
private boolean talismanActionBarMessages;
|
||||
|
||||
@ -109,6 +110,7 @@ public final class SlimefunRegistry {
|
||||
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
|
||||
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
||||
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
||||
disableLearningAnimation = cfg.getBoolean("researches.disable-learning-animation");
|
||||
logDuplicateBlockEntries = cfg.getBoolean("options.log-duplicate-block-entries");
|
||||
talismanActionBarMessages = cfg.getBoolean("talismans.use-actionbar");
|
||||
}
|
||||
@ -238,6 +240,10 @@ public final class SlimefunRegistry {
|
||||
return researchFireworks;
|
||||
}
|
||||
|
||||
public boolean isLearningAnimationDisabled() {
|
||||
return disableLearningAnimation;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a {@link List} of every enabled {@link MultiBlock}.
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||
import io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings;
|
||||
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide;
|
||||
@ -18,7 +19,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
/**
|
||||
* This interface is used for the different implementations that add behaviour
|
||||
* to the {@link SlimefunGuide}.
|
||||
*
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see SlimefunGuideMode
|
||||
@ -30,7 +31,7 @@ public interface SlimefunGuideImplementation {
|
||||
/**
|
||||
* Every {@link SlimefunGuideImplementation} can be associated with a
|
||||
* {@link SlimefunGuideMode}.
|
||||
*
|
||||
*
|
||||
* @return The mode this {@link SlimefunGuideImplementation} represents
|
||||
*/
|
||||
@Nonnull
|
||||
@ -40,7 +41,7 @@ public interface SlimefunGuideImplementation {
|
||||
* Returns the {@link ItemStack} representation for this {@link SlimefunGuideImplementation}.
|
||||
* In other words: The {@link ItemStack} you hold in your hand and that you use to
|
||||
* open your {@link SlimefunGuide}
|
||||
*
|
||||
*
|
||||
* @return The {@link ItemStack} representation for this {@link SlimefunGuideImplementation}
|
||||
*/
|
||||
@Nonnull
|
||||
@ -63,7 +64,9 @@ public interface SlimefunGuideImplementation {
|
||||
research.unlock(p, true, callback);
|
||||
} else {
|
||||
p.setLevel(p.getLevel() - research.getCost());
|
||||
research.unlock(p, false, callback);
|
||||
boolean skipLearningAnimation = SlimefunPlugin.getRegistry().isLearningAnimationDisabled()
|
||||
|| !SlimefunGuideSettings.hasLearningAnimationEnabled(p);
|
||||
research.unlock(p, skipLearningAnimation, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,55 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.guide.options;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class LearningAnimationOption implements SlimefunGuideOption<Boolean> {
|
||||
|
||||
@Override
|
||||
public SlimefunAddon getAddon() {
|
||||
return SlimefunPlugin.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return new NamespacedKey(SlimefunPlugin.instance(), "research_learning_animation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {
|
||||
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");
|
||||
return Optional.of(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Player p, ItemStack guide) {
|
||||
setSelectedOption(p, guide, !getSelectedOption(p, guide).orElse(true));
|
||||
SlimefunGuideSettings.openSettings(p, guide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Boolean> getSelectedOption(Player p, ItemStack guide) {
|
||||
NamespacedKey key = getKey();
|
||||
boolean value = !PersistentDataAPI.hasByte(p, key) || PersistentDataAPI.getByte(p, key) == (byte) 1;
|
||||
return Optional.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedOption(Player p, ItemStack guide, Boolean value) {
|
||||
PersistentDataAPI.setByte(p, getKey(), (byte) (value ? 1 : 0));
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,7 @@ public final class SlimefunGuideSettings {
|
||||
static {
|
||||
options.add(new GuideModeOption());
|
||||
options.add(new FireworksOption());
|
||||
options.add(new LearningAnimationOption());
|
||||
options.add(new PlayerLanguageOption());
|
||||
}
|
||||
|
||||
@ -249,4 +250,25 @@ public final class SlimefunGuideSettings {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if the given {@link Player} has enabled the {@link LearningAnimationOption}
|
||||
* in their {@link SlimefunGuide}.
|
||||
* If they enabled this setting, they will see messages in chat about the progress of their {@link Research}.
|
||||
*
|
||||
* @param p The {@link Player}
|
||||
*
|
||||
* @return Whether this {@link Player} wants to info messages in chat when unlocking a {@link Research}
|
||||
*/
|
||||
public static boolean hasLearningAnimationEnabled(@Nonnull Player p) {
|
||||
for (SlimefunGuideOption<?> option : options) {
|
||||
if (option instanceof LearningAnimationOption) {
|
||||
LearningAnimationOption learningAnimation = (LearningAnimationOption) option;
|
||||
ItemStack guide = SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE);
|
||||
return learningAnimation.getSelectedOption(p, guide).orElse(true);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ guide:
|
||||
researches:
|
||||
free-in-creative-mode: true
|
||||
enable-fireworks: true
|
||||
disable-learning-animation: false
|
||||
|
||||
URID:
|
||||
info-delay: 3000
|
||||
|
@ -47,7 +47,7 @@ class TestResearchUnlocking {
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
latch.await(10, TimeUnit.SECONDS);
|
||||
latch.await(instant ? 1 : 10, TimeUnit.SECONDS);
|
||||
return ref.get();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user