Allow defaults in sound groups, allow multiple sounds in the same group
This commit is contained in:
parent
5a05dffdce
commit
3d4329942c
@ -7,6 +7,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
|||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -26,7 +27,9 @@ public class SoundGroup {
|
|||||||
private final static LinkedHashMap<String, SoundGroup> groups = new LinkedHashMap<>();
|
private final static LinkedHashMap<String, SoundGroup> groups = new LinkedHashMap<>();
|
||||||
private float damageSoundVolume = 1F;
|
private float damageSoundVolume = 1F;
|
||||||
@Getter
|
@Getter
|
||||||
private final LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
|
private final LinkedHashMap<Object, SoundType> disguiseSoundTypes = new LinkedHashMap<>();
|
||||||
|
@Getter
|
||||||
|
private final LinkedHashMap<SoundType, Object[]> disguiseSounds = new LinkedHashMap<>();
|
||||||
private boolean customSounds;
|
private boolean customSounds;
|
||||||
|
|
||||||
public SoundGroup(String name) {
|
public SoundGroup(String name) {
|
||||||
@ -53,7 +56,18 @@ public class SoundGroup {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disguiseSounds.put(sound, type);
|
disguiseSoundTypes.putIfAbsent(sound, type);
|
||||||
|
|
||||||
|
if (disguiseSounds.containsKey(type)) {
|
||||||
|
Object[] array = disguiseSounds.get(type);
|
||||||
|
|
||||||
|
array = Arrays.copyOf(array, array.length + 1);
|
||||||
|
array[array.length - 1] = sound;
|
||||||
|
|
||||||
|
disguiseSounds.put(type, array);
|
||||||
|
} else {
|
||||||
|
disguiseSounds.put(type, new Object[]{sound});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDamageAndIdleSoundVolume() {
|
public float getDamageAndIdleSoundVolume() {
|
||||||
@ -73,38 +87,27 @@ public class SoundGroup {
|
|||||||
return getRandomSound(type);
|
return getRandomSound(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
Object[] sounds = disguiseSounds.get(type);
|
||||||
if (entry.getValue() != type) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (sounds == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sounds[0];
|
||||||
|
}
|
||||||
|
|
||||||
private Object getRandomSound(SoundType type) {
|
private Object getRandomSound(SoundType type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object[] sounds = new Object[disguiseSounds.size()];
|
Object[] sounds = disguiseSounds.get(type);
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
if (sounds == null) {
|
||||||
if (entry.getValue() != type) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sounds[i++] = entry.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sounds[RandomUtils.nextInt(i)];
|
return sounds[RandomUtils.nextInt(sounds.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundType getSound(Object sound) {
|
public SoundType getSound(Object sound) {
|
||||||
@ -112,7 +115,7 @@ public class SoundGroup {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return disguiseSounds.get(sound);
|
return disguiseSoundTypes.get(sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,8 +62,27 @@ public class SoundManager {
|
|||||||
|
|
||||||
for (String sound : list) {
|
for (String sound : list) {
|
||||||
if (!sound.matches(".+:.+")) {
|
if (!sound.matches(".+:.+")) {
|
||||||
DisguiseUtilities.getLogger()
|
SoundGroup subGroup = SoundGroup.getGroup(sound);
|
||||||
.warning("Invalid sound '" + sound + "'! Must be a minecraft:sound.name");
|
|
||||||
|
if (subGroup == null) {
|
||||||
|
DisguiseUtilities.getLogger().warning("Invalid sound '" + sound +
|
||||||
|
"'! Must be a minecraft:sound.name or SoundGroup name!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] sounds = subGroup.getDisguiseSounds().get(type);
|
||||||
|
|
||||||
|
if (sounds == null) {
|
||||||
|
DisguiseUtilities.getLogger().warning(
|
||||||
|
"Sound group '" + sound + "' does not contain a category for " + type +
|
||||||
|
"! Can't use as default in " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object obj : sounds) {
|
||||||
|
group.addSound(obj, type);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
GroupName:
|
GroupName:
|
||||||
# If you don't set one of these options, or it is empty. Then no sound will be played for that sound type
|
# If you don't set one of these options, or it is empty. Then no sound will be played for that sound type
|
||||||
# So if hurt is missing, it won't play a hurt noise
|
# So if hurt is missing, it won't play a hurt noise
|
||||||
|
# Alternatively, you could use "COW" which refers to the "COW" soundgroup, and loads the category from that!
|
||||||
|
# Idle:
|
||||||
|
# - COW
|
||||||
Idle:
|
Idle:
|
||||||
- minecraft:some.idle.sound
|
- minecraft:some.idle.sound
|
||||||
Hurt:
|
Hurt:
|
||||||
|
Loading…
Reference in New Issue
Block a user