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 lombok.Getter;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by libraryaddict on 23/05/2020.
|
* Created by libraryaddict on 23/05/2020.
|
||||||
@ -26,9 +29,17 @@ public class SoundGroup {
|
|||||||
private float damageSoundVolume = 1F;
|
private float damageSoundVolume = 1F;
|
||||||
@Getter
|
@Getter
|
||||||
private final LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
|
private final LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
|
||||||
|
private boolean customSounds;
|
||||||
|
|
||||||
public SoundGroup(String name) {
|
public SoundGroup(String name) {
|
||||||
groups.put(name, this);
|
groups.put(name, this);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DisguiseType.valueOf(name);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
customSounds = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSound(Object sound, SoundType type) {
|
public void addSound(Object sound, SoundType type) {
|
||||||
@ -60,6 +71,10 @@ public class SoundGroup {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (customSounds) {
|
||||||
|
return getRandomSound(type);
|
||||||
|
}
|
||||||
|
|
||||||
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
||||||
if (entry.getValue() != type) {
|
if (entry.getValue() != type) {
|
||||||
continue;
|
continue;
|
||||||
@ -71,6 +86,29 @@ public class SoundGroup {
|
|||||||
return null;
|
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) {
|
public SoundType getSound(Object sound) {
|
||||||
if (sound == null) {
|
if (sound == null) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user