From e853d02c7e1a691b1d3892e5b5ffe9e4f6a7bab7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 24 May 2020 13:10:48 +1200 Subject: [PATCH] Some more sounds functionality --- .../commands/libsdisguises/LDReload.java | 2 ++ .../disguise/utilities/params/ParamInfo.java | 4 +-- .../utilities/params/ParamInfoTypes.java | 6 +---- .../types/custom/ParamInfoSoundGroup.java | 25 +++++++++++++++++-- .../disguise/utilities/sounds/SoundGroup.java | 2 +- .../utilities/sounds/SoundManager.java | 3 +++ 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java index f49381c1..b80af15d 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDReload.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.commands.libsdisguises; import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.utilities.sounds.SoundManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.bukkit.command.CommandSender; @@ -24,6 +25,7 @@ public class LDReload implements LDCommand { @Override public void onCommand(CommandSender sender, String[] args) { DisguiseConfig.loadConfig(); + new SoundManager().load(); sender.sendMessage(LibsMsg.RELOADED_CONFIG.get()); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfo.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfo.java index ec914e89..7fba651b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfo.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfo.java @@ -37,7 +37,7 @@ public abstract class ParamInfo { public ParamInfo(Class paramClass, String name, String descriptiveName, String description, Enum[] possibleValues) { this(paramClass, name, descriptiveName, description); - this.possibleValues = new HashMap<>(); + this.possibleValues = new LinkedHashMap<>(); for (Enum anEnum : possibleValues) { this.getValues().put(anEnum.name(), anEnum); @@ -52,7 +52,7 @@ public abstract class ParamInfo { Map possibleValues) { this(paramClass, name, descriptiveName, description); - this.possibleValues = new HashMap<>(); + this.possibleValues = new LinkedHashMap<>(); this.possibleValues.putAll(possibleValues); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java index 9ba7abff..be26afe7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java @@ -35,11 +35,7 @@ public class ParamInfoTypes { } public ParamInfoSoundGroup getParamInfoSoundGroup() { - HashMap possibleSoundGroups = new HashMap<>(); - - SoundGroup.getGroups().keySet().forEach(key -> possibleSoundGroups.put(key, key)); - - return new ParamInfoSoundGroup(possibleSoundGroups); + return new ParamInfoSoundGroup(); } /** diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoSoundGroup.java b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoSoundGroup.java index ed263bec..b4d2ea8b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoSoundGroup.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoSoundGroup.java @@ -1,14 +1,35 @@ package me.libraryaddict.disguise.utilities.params.types.custom; import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum; +import me.libraryaddict.disguise.utilities.sounds.SoundGroup; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; /** * Created by libraryaddict on 23/05/2020. */ public class ParamInfoSoundGroup extends ParamInfoEnum { - public ParamInfoSoundGroup(Map possibleValues) { - super(String.class, "SoundGroup", "A group of sounds", possibleValues); + public ParamInfoSoundGroup() { + super(String.class, "SoundGroup", "A group of sounds", new HashMap<>()); + + recalculate(); + } + + public void recalculate() { + LinkedHashMap possibleSoundGroups = new LinkedHashMap<>(); + + ArrayList list = new ArrayList<>(SoundGroup.getGroups().keySet()); + + list.sort(String.CASE_INSENSITIVE_ORDER); + + for (String s : list) { + possibleSoundGroups.put(s, SoundGroup.getGroup(s)); + } + + getValues().clear(); + getValues().putAll(possibleSoundGroups); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java index f2b003a3..8a5c0a62 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java @@ -25,7 +25,7 @@ public class SoundGroup { } @Getter - private final static HashMap groups = new HashMap<>(); + private final static LinkedHashMap groups = new LinkedHashMap<>(); private float damageSoundVolume = 1F; @Getter private final LinkedHashMap disguiseSounds = new LinkedHashMap<>(); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java index 34e271db..453cf40b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities.sounds; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -16,8 +17,10 @@ import java.util.stream.Collectors; */ public class SoundManager { public void load() { + SoundGroup.getGroups().clear(); loadSounds(); loadCustomSounds(); + ParamInfoManager.getParamInfoSoundGroup().recalculate(); } private void loadCustomSounds() {