mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45: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 enableResearches;
|
||||||
private boolean freeCreativeResearches;
|
private boolean freeCreativeResearches;
|
||||||
private boolean researchFireworks;
|
private boolean researchFireworks;
|
||||||
|
private boolean disableLearningAnimation;
|
||||||
private boolean logDuplicateBlockEntries;
|
private boolean logDuplicateBlockEntries;
|
||||||
private boolean talismanActionBarMessages;
|
private boolean talismanActionBarMessages;
|
||||||
|
|
||||||
@ -109,6 +110,7 @@ public final class SlimefunRegistry {
|
|||||||
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
|
backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
|
||||||
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
|
||||||
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
|
||||||
|
disableLearningAnimation = cfg.getBoolean("researches.disable-learning-animation");
|
||||||
logDuplicateBlockEntries = cfg.getBoolean("options.log-duplicate-block-entries");
|
logDuplicateBlockEntries = cfg.getBoolean("options.log-duplicate-block-entries");
|
||||||
talismanActionBarMessages = cfg.getBoolean("talismans.use-actionbar");
|
talismanActionBarMessages = cfg.getBoolean("talismans.use-actionbar");
|
||||||
}
|
}
|
||||||
@ -238,6 +240,10 @@ public final class SlimefunRegistry {
|
|||||||
return researchFireworks;
|
return researchFireworks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLearningAnimationDisabled() {
|
||||||
|
return disableLearningAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a {@link List} of every enabled {@link MultiBlock}.
|
* 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 org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
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.core.researching.Research;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide;
|
import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide;
|
||||||
@ -63,7 +64,9 @@ public interface SlimefunGuideImplementation {
|
|||||||
research.unlock(p, true, callback);
|
research.unlock(p, true, callback);
|
||||||
} else {
|
} else {
|
||||||
p.setLevel(p.getLevel() - research.getCost());
|
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 {
|
static {
|
||||||
options.add(new GuideModeOption());
|
options.add(new GuideModeOption());
|
||||||
options.add(new FireworksOption());
|
options.add(new FireworksOption());
|
||||||
|
options.add(new LearningAnimationOption());
|
||||||
options.add(new PlayerLanguageOption());
|
options.add(new PlayerLanguageOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,4 +250,25 @@ public final class SlimefunGuideSettings {
|
|||||||
return true;
|
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:
|
researches:
|
||||||
free-in-creative-mode: true
|
free-in-creative-mode: true
|
||||||
enable-fireworks: true
|
enable-fireworks: true
|
||||||
|
disable-learning-animation: false
|
||||||
|
|
||||||
URID:
|
URID:
|
||||||
info-delay: 3000
|
info-delay: 3000
|
||||||
|
@ -47,7 +47,7 @@ class TestResearchUnlocking {
|
|||||||
latch.countDown();
|
latch.countDown();
|
||||||
});
|
});
|
||||||
|
|
||||||
latch.await(10, TimeUnit.SECONDS);
|
latch.await(instant ? 1 : 10, TimeUnit.SECONDS);
|
||||||
return ref.get();
|
return ref.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user