mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-04 08:59:47 +01:00
Add /dhelp disguisesound
This commit is contained in:
parent
dcbcbc79f4
commit
860a6e4a03
@ -2,12 +2,15 @@ package me.libraryaddict.disguise.utilities.sounds;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 23/05/2020.
|
||||
@ -26,9 +29,17 @@ public class SoundGroup {
|
||||
private float damageSoundVolume = 1F;
|
||||
@Getter
|
||||
private final LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
|
||||
private boolean customSounds;
|
||||
|
||||
public SoundGroup(String name) {
|
||||
groups.put(name, this);
|
||||
|
||||
try {
|
||||
DisguiseType.valueOf(name);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
customSounds = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void addSound(Object sound, SoundType type) {
|
||||
@ -60,6 +71,10 @@ public class SoundGroup {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (customSounds) {
|
||||
return getRandomSound(type);
|
||||
}
|
||||
|
||||
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
||||
if (entry.getValue() != type) {
|
||||
continue;
|
||||
@ -71,6 +86,29 @@ public class SoundGroup {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object getRandomSound(SoundType type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object[] sounds = new Object[disguiseSounds.size()];
|
||||
int i = 0;
|
||||
|
||||
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
||||
if (entry.getValue() != type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sounds[i++] = entry.getKey();
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sounds[RandomUtils.nextInt(i)];
|
||||
}
|
||||
|
||||
public SoundType getSound(Object sound) {
|
||||
if (sound == null) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user