Add ability to change the sounds for a disguise to whatever you like
This commit is contained in:
parent
e77a28c258
commit
37e7a0bac7
@ -25,6 +25,7 @@ import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
|||||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherSanitizer;
|
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherSanitizer;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundManager;
|
||||||
import me.libraryaddict.disguise.utilities.updates.UpdateChecker;
|
import me.libraryaddict.disguise.utilities.updates.UpdateChecker;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -119,6 +120,7 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReflectionManager.init();
|
ReflectionManager.init();
|
||||||
|
new SoundManager().load();
|
||||||
|
|
||||||
PacketsManager.init();
|
PacketsManager.init();
|
||||||
DisguiseUtilities.init();
|
DisguiseUtilities.init();
|
||||||
|
@ -105,6 +105,9 @@ public abstract class Disguise {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private boolean dynamicName;
|
private boolean dynamicName;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private String soundGroup;
|
||||||
|
|
||||||
public Disguise(DisguiseType disguiseType) {
|
public Disguise(DisguiseType disguiseType) {
|
||||||
this.disguiseType = disguiseType;
|
this.disguiseType = disguiseType;
|
||||||
@ -211,6 +214,7 @@ public abstract class Disguise {
|
|||||||
disguise.setModifyBoundingBox(isModifyBoundingBox());
|
disguise.setModifyBoundingBox(isModifyBoundingBox());
|
||||||
disguise.multiName = Arrays.copyOf(multiName, multiName.length);
|
disguise.multiName = Arrays.copyOf(multiName, multiName.length);
|
||||||
disguise.setDynamicName(isDynamicName());
|
disguise.setDynamicName(isDynamicName());
|
||||||
|
disguise.setSoundGroup(getSoundGroup());
|
||||||
|
|
||||||
if (getWatcher() != null && disguise.getWatcher() == null) {
|
if (getWatcher() != null && disguise.getWatcher() == null) {
|
||||||
disguise.setWatcher(getWatcher().clone(disguise));
|
disguise.setWatcher(getWatcher().clone(disguise));
|
||||||
|
@ -1,309 +0,0 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.LibsDisguises;
|
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only living disguises go in here!
|
|
||||||
*/
|
|
||||||
public enum DisguiseSound {
|
|
||||||
ARMOR_STAND,
|
|
||||||
|
|
||||||
ARROW,
|
|
||||||
|
|
||||||
BAT,
|
|
||||||
|
|
||||||
BEE,
|
|
||||||
|
|
||||||
BLAZE,
|
|
||||||
|
|
||||||
BOAT,
|
|
||||||
|
|
||||||
CAVE_SPIDER,
|
|
||||||
|
|
||||||
CHICKEN,
|
|
||||||
|
|
||||||
COD,
|
|
||||||
|
|
||||||
COW,
|
|
||||||
|
|
||||||
CREEPER,
|
|
||||||
|
|
||||||
DOLPHIN,
|
|
||||||
|
|
||||||
DONKEY,
|
|
||||||
|
|
||||||
DROWNED,
|
|
||||||
|
|
||||||
ELDER_GUARDIAN,
|
|
||||||
|
|
||||||
ENDER_DRAGON,
|
|
||||||
|
|
||||||
ENDERMAN,
|
|
||||||
|
|
||||||
ENDERMITE,
|
|
||||||
|
|
||||||
EVOKER,
|
|
||||||
|
|
||||||
EVOKER_FANGS,
|
|
||||||
|
|
||||||
GHAST,
|
|
||||||
|
|
||||||
GIANT,
|
|
||||||
|
|
||||||
GUARDIAN,
|
|
||||||
|
|
||||||
HORSE,
|
|
||||||
|
|
||||||
HUSK,
|
|
||||||
|
|
||||||
ILLUSIONER,
|
|
||||||
|
|
||||||
IRON_GOLEM,
|
|
||||||
|
|
||||||
LLAMA,
|
|
||||||
|
|
||||||
MAGMA_CUBE,
|
|
||||||
|
|
||||||
MULE,
|
|
||||||
|
|
||||||
MUSHROOM_COW,
|
|
||||||
|
|
||||||
OCELOT,
|
|
||||||
|
|
||||||
PARROT,
|
|
||||||
|
|
||||||
PIG,
|
|
||||||
|
|
||||||
PIG_ZOMBIE,
|
|
||||||
|
|
||||||
PLAYER,
|
|
||||||
|
|
||||||
PHANTOM,
|
|
||||||
|
|
||||||
POLAR_BEAR,
|
|
||||||
|
|
||||||
PUFFERFISH,
|
|
||||||
|
|
||||||
RABBIT,
|
|
||||||
|
|
||||||
SALMON,
|
|
||||||
|
|
||||||
SHEEP,
|
|
||||||
|
|
||||||
SHULKER,
|
|
||||||
|
|
||||||
SILVERFISH,
|
|
||||||
|
|
||||||
SKELETON,
|
|
||||||
|
|
||||||
SKELETON_HORSE,
|
|
||||||
|
|
||||||
SLIME,
|
|
||||||
|
|
||||||
SNOWMAN,
|
|
||||||
|
|
||||||
SPIDER,
|
|
||||||
|
|
||||||
STRAY,
|
|
||||||
|
|
||||||
SQUID,
|
|
||||||
|
|
||||||
TROPICAL_FISH,
|
|
||||||
|
|
||||||
TURTLE,
|
|
||||||
|
|
||||||
VEX,
|
|
||||||
|
|
||||||
VILLAGER,
|
|
||||||
|
|
||||||
VINDICATOR,
|
|
||||||
|
|
||||||
WITCH,
|
|
||||||
|
|
||||||
WITHER,
|
|
||||||
|
|
||||||
WITHER_SKELETON,
|
|
||||||
|
|
||||||
WOLF,
|
|
||||||
|
|
||||||
ZOMBIE,
|
|
||||||
|
|
||||||
ZOMBIE_HORSE,
|
|
||||||
|
|
||||||
ZOMBIE_VILLAGER;
|
|
||||||
|
|
||||||
public enum SoundType {
|
|
||||||
CANCEL,
|
|
||||||
DEATH,
|
|
||||||
HURT,
|
|
||||||
IDLE,
|
|
||||||
STEP
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCODED_WITH_SOUNDS")) {
|
|
||||||
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
for (String s : lines) {
|
|
||||||
String[] spl = s.split(":", -1);
|
|
||||||
|
|
||||||
DisguiseSound sound = DisguiseSound.valueOf(spl[0]);
|
|
||||||
|
|
||||||
for (int i = 1; i <= SoundType.values().length; i++) {
|
|
||||||
if (spl[i].isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] split = spl[i].split(",");
|
|
||||||
|
|
||||||
for (String sName : split) {
|
|
||||||
try {
|
|
||||||
sound.addSound(Sound.valueOf(sName), SoundType.values()[i - 1]);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DisguiseSound getType(String name) {
|
|
||||||
try {
|
|
||||||
return valueOf(name);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private float damageSoundVolume = 1F;
|
|
||||||
private LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
private Sound parseSound(String name) {
|
|
||||||
try {
|
|
||||||
return Sound.valueOf(name);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addSound(Object sound, SoundType type) {
|
|
||||||
if (sound == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sound instanceof String[]) {
|
|
||||||
for (String s : (String[]) sound) {
|
|
||||||
Sound so = parseSound(s);
|
|
||||||
|
|
||||||
if (so == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
addSound(so, type);
|
|
||||||
}
|
|
||||||
} else if (sound instanceof String) {
|
|
||||||
Sound so = parseSound((String) sound);
|
|
||||||
|
|
||||||
if (so == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
addSound(so, type);
|
|
||||||
} else if (sound instanceof Sound[]) {
|
|
||||||
for (Sound s : (Sound[]) sound) {
|
|
||||||
if (s == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
addSound(s, type);
|
|
||||||
}
|
|
||||||
} else if (sound instanceof Sound) {
|
|
||||||
addSound((Sound) sound, type);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Was given an unknown object " + sound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addSound(Sound sound, SoundType type) {
|
|
||||||
Object soundEffect = ReflectionManager.getCraftSound(sound);
|
|
||||||
|
|
||||||
if (disguiseSounds.containsKey(soundEffect)) {
|
|
||||||
DisguiseUtilities.getLogger().severe("Already doing " + sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
disguiseSounds.put(soundEffect, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getDamageAndIdleSoundVolume() {
|
|
||||||
return damageSoundVolume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDamageAndIdleSoundVolume(float strength) {
|
|
||||||
this.damageSoundVolume = strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSound(SoundType type) {
|
|
||||||
if (type == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
|
||||||
if (entry.getValue() != type) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundType getSound(Object sound) {
|
|
||||||
if (sound == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return disguiseSounds.get(sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to check if this sound name is owned by this disguise sound.
|
|
||||||
*/
|
|
||||||
public SoundType getType(Object sound, boolean ignoreDamage) {
|
|
||||||
if (sound == null) {
|
|
||||||
return SoundType.CANCEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundType soundType = getSound(sound);
|
|
||||||
|
|
||||||
if (soundType == SoundType.DEATH || (ignoreDamage && soundType == SoundType.HURT)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return soundType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelSound(String sound) {
|
|
||||||
return getSound(sound) == SoundType.CANCEL;
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,10 +12,10 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup.SoundType;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -61,7 +61,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
SoundType soundType = null;
|
SoundType soundType = null;
|
||||||
|
|
||||||
Entity disguisedEntity = null;
|
Entity disguisedEntity = null;
|
||||||
DisguiseSound entitySound = null;
|
SoundGroup entitySound = null;
|
||||||
Object soundEffectObj = mods.read(0);
|
Object soundEffectObj = mods.read(0);
|
||||||
|
|
||||||
Disguise disguise = null;
|
Disguise disguise = null;
|
||||||
@ -89,7 +89,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
entitySound = DisguiseSound.getType(entity.getType().name());
|
entitySound = SoundGroup.getGroup(entity.getType().name());
|
||||||
|
|
||||||
if (entitySound == null) {
|
if (entitySound == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -148,7 +148,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
(disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
|
(disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
|
||||||
Object sound = null;
|
Object sound = null;
|
||||||
|
|
||||||
DisguiseSound disguiseSound = DisguiseSound.getType(disguise.getType().name());
|
SoundGroup disguiseSound = SoundGroup.getGroup(disguise);
|
||||||
|
|
||||||
if (disguiseSound != null) {
|
if (disguiseSound != null) {
|
||||||
sound = disguiseSound.getSound(soundType);
|
sound = disguiseSound.getSound(soundType);
|
||||||
@ -259,7 +259,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
|
|
||||||
if (!disguise.getType().isPlayer() &&
|
if (!disguise.getType().isPlayer() &&
|
||||||
(disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
|
(disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
|
||||||
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
|
SoundGroup disSound = SoundGroup.getGroup(entity.getType().name());
|
||||||
|
|
||||||
if (disSound == null)
|
if (disSound == null)
|
||||||
return;
|
return;
|
||||||
@ -295,7 +295,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disSound = DisguiseSound.getType(disguise.getType().name());
|
disSound = SoundGroup.getGroup(disguise);
|
||||||
|
|
||||||
if (disSound != null) {
|
if (disSound != null) {
|
||||||
Object sound = disSound.getSound(soundType);
|
Object sound = disSound.getSound(soundType);
|
||||||
|
@ -8,6 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock;
|
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock;
|
||||||
|
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoSoundGroup;
|
||||||
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
||||||
import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods;
|
import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -25,6 +26,8 @@ public class ParamInfoManager {
|
|||||||
private static DisguiseMethods disguiseMethods;
|
private static DisguiseMethods disguiseMethods;
|
||||||
@Getter
|
@Getter
|
||||||
private static ParamInfoItemBlock paramInfoItemBlock;
|
private static ParamInfoItemBlock paramInfoItemBlock;
|
||||||
|
@Getter
|
||||||
|
private static ParamInfoSoundGroup paramInfoSoundGroup;
|
||||||
|
|
||||||
public static List<ParamInfo> getParamInfos() {
|
public static List<ParamInfo> getParamInfos() {
|
||||||
return paramList;
|
return paramList;
|
||||||
@ -45,6 +48,10 @@ public class ParamInfoManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ParamInfo getParamInfo(Method method) {
|
public static ParamInfo getParamInfo(Method method) {
|
||||||
|
if (method.getName().equals("setSoundGroup")) {
|
||||||
|
return getParamInfoSoundGroup();
|
||||||
|
}
|
||||||
|
|
||||||
if (method.getDeclaringClass() == FallingBlockWatcher.class &&
|
if (method.getDeclaringClass() == FallingBlockWatcher.class &&
|
||||||
method.getParameterTypes()[0] == ItemStack.class) {
|
method.getParameterTypes()[0] == ItemStack.class) {
|
||||||
return getParamInfoItemBlock();
|
return getParamInfoItemBlock();
|
||||||
@ -84,6 +91,7 @@ public class ParamInfoManager {
|
|||||||
ParamInfoTypes infoTypes = new ParamInfoTypes();
|
ParamInfoTypes infoTypes = new ParamInfoTypes();
|
||||||
paramList = infoTypes.getParamInfos();
|
paramList = infoTypes.getParamInfos();
|
||||||
paramInfoItemBlock = infoTypes.getParamInfoBlock();
|
paramInfoItemBlock = infoTypes.getParamInfoBlock();
|
||||||
|
paramInfoSoundGroup = infoTypes.getParamInfoSoundGroup();
|
||||||
disguiseMethods = new DisguiseMethods();
|
disguiseMethods = new DisguiseMethods();
|
||||||
|
|
||||||
//paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()));
|
//paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()));
|
||||||
@ -112,7 +120,7 @@ public class ParamInfoManager {
|
|||||||
// Add these last as it's what we want to present to be called the least
|
// Add these last as it's what we want to present to be called the least
|
||||||
for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf",
|
for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf",
|
||||||
"setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires", "setNotifyBar",
|
"setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires", "setNotifyBar",
|
||||||
"setBossBarColor", "setBossBarStyle", "setTallDisguisesVisible", "setDynamicName"}) {
|
"setBossBarColor", "setBossBarStyle", "setTallDisguisesVisible", "setDynamicName", "setSoundGroup"}) {
|
||||||
try {
|
try {
|
||||||
Class cl = boolean.class;
|
Class cl = boolean.class;
|
||||||
|
|
||||||
@ -129,6 +137,9 @@ public class ParamInfoManager {
|
|||||||
case "setBossBarStyle":
|
case "setBossBarStyle":
|
||||||
cl = BarStyle.class;
|
cl = BarStyle.class;
|
||||||
break;
|
break;
|
||||||
|
case "setSoundGroup":
|
||||||
|
cl = String.class;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
|
|||||||
import me.libraryaddict.disguise.utilities.params.types.base.*;
|
import me.libraryaddict.disguise.utilities.params.types.base.*;
|
||||||
import me.libraryaddict.disguise.utilities.params.types.custom.*;
|
import me.libraryaddict.disguise.utilities.params.types.custom.*;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -33,6 +34,14 @@ public class ParamInfoTypes {
|
|||||||
"An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials());
|
"An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ParamInfoSoundGroup getParamInfoSoundGroup() {
|
||||||
|
HashMap<String, Object> possibleSoundGroups = new HashMap<>();
|
||||||
|
|
||||||
|
SoundGroup.getGroups().keySet().forEach(key -> possibleSoundGroups.put(key, key));
|
||||||
|
|
||||||
|
return new ParamInfoSoundGroup(possibleSoundGroups);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor values are listed here for continuity
|
* Constructor values are listed here for continuity
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package me.libraryaddict.disguise.utilities.params.types.custom;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by libraryaddict on 23/05/2020.
|
||||||
|
*/
|
||||||
|
public class ParamInfoSoundGroup extends ParamInfoEnum {
|
||||||
|
public ParamInfoSoundGroup(Map<String, Object> possibleValues) {
|
||||||
|
super(String.class, "SoundGroup", "A group of sounds", possibleValues);
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,10 @@ import me.libraryaddict.disguise.DisguiseConfig;
|
|||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.disguisetypes.*;
|
import me.libraryaddict.disguise.disguisetypes.*;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseValues;
|
import me.libraryaddict.disguise.utilities.DisguiseValues;
|
||||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
@ -1726,7 +1726,7 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
||||||
|
|
||||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
||||||
|
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
sound.setDamageAndIdleSoundVolume(1f);
|
sound.setDamageAndIdleSoundVolume(1f);
|
||||||
@ -1820,7 +1820,7 @@ public class ReflectionManager {
|
|||||||
" at index " + index.getIndex());
|
" at index " + index.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
||||||
|
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities.sounds;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup.SoundType;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -229,8 +232,7 @@ public enum DisguiseSoundEnums {
|
|||||||
Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
|
Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
|
||||||
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
|
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
|
||||||
|
|
||||||
@Getter
|
private SoundGroup group = new SoundGroup(name());
|
||||||
private LinkedHashMap<Sound, SoundType> disguiseSounds = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
DisguiseSoundEnums(Object hurt, Object step, Object death, Object idle, Object... sounds) {
|
DisguiseSoundEnums(Object hurt, Object step, Object death, Object idle, Object... sounds) {
|
||||||
addSound(hurt, SoundType.HURT);
|
addSound(hurt, SoundType.HURT);
|
||||||
@ -264,6 +266,6 @@ public enum DisguiseSoundEnums {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addSound(Sound sound, SoundType type) {
|
private void addSound(Sound sound, SoundType type) {
|
||||||
disguiseSounds.put(sound, type);
|
group.addSound(ReflectionManager.getCraftSound(sound), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
package me.libraryaddict.disguise.utilities.sounds;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by libraryaddict on 23/05/2020.
|
||||||
|
*/
|
||||||
|
public class SoundGroup {
|
||||||
|
public enum SoundType {
|
||||||
|
CANCEL,
|
||||||
|
DEATH,
|
||||||
|
HURT,
|
||||||
|
IDLE,
|
||||||
|
STEP
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final static HashMap<String, SoundGroup> groups = new HashMap<>();
|
||||||
|
private float damageSoundVolume = 1F;
|
||||||
|
@Getter
|
||||||
|
private final LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public SoundGroup(String name) {
|
||||||
|
groups.put(name, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSound(Object sound, SoundType type) {
|
||||||
|
if (sound instanceof String) {
|
||||||
|
sound = ReflectionManager.createMinecraftKey((String) sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
disguiseSounds.put(sound, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getDamageAndIdleSoundVolume() {
|
||||||
|
return damageSoundVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDamageAndIdleSoundVolume(float strength) {
|
||||||
|
this.damageSoundVolume = strength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getSound(SoundType type) {
|
||||||
|
if (type == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
|
||||||
|
if (entry.getValue() != type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoundType getSound(Object sound) {
|
||||||
|
if (sound == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return disguiseSounds.get(sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to check if this sound name is owned by this disguise sound.
|
||||||
|
*/
|
||||||
|
public SoundType getType(Object sound, boolean ignoreDamage) {
|
||||||
|
if (sound == null) {
|
||||||
|
return SoundType.CANCEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundType soundType = getSound(sound);
|
||||||
|
|
||||||
|
if (soundType == SoundType.DEATH || (ignoreDamage && soundType == SoundType.HURT)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return soundType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelSound(String sound) {
|
||||||
|
return getSound(sound) == SoundType.CANCEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SoundGroup getGroup(Disguise disguise) {
|
||||||
|
if (disguise.getSoundGroup() != null) {
|
||||||
|
return getGroup(disguise.getSoundGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
return getGroup(disguise.getType().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SoundGroup getGroup(String name) {
|
||||||
|
return groups.get(name);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
package me.libraryaddict.disguise.utilities.sounds;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by libraryaddict on 23/05/2020.
|
||||||
|
*/
|
||||||
|
public class SoundManager {
|
||||||
|
public void load() {
|
||||||
|
loadSounds();
|
||||||
|
loadCustomSounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadCustomSounds() {
|
||||||
|
File f = new File(LibsDisguises.getInstance().getDataFolder(), "sounds.yml");
|
||||||
|
|
||||||
|
if (!f.exists()) {
|
||||||
|
LibsDisguises.getInstance().saveResource("sounds.yml", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
|
||||||
|
|
||||||
|
for (String key : config.getKeys(false)) {
|
||||||
|
if (!config.isConfigurationSection(key) || key.equals("GroupName")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SoundGroup.getGroups().keySet().stream().anyMatch(k -> k.equalsIgnoreCase(key))) {
|
||||||
|
DisguiseUtilities.getLogger().warning("The SoundGroup " + key + " has already been registered!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundGroup group = new SoundGroup(key);
|
||||||
|
ConfigurationSection section = config.getConfigurationSection(key);
|
||||||
|
|
||||||
|
for (SoundGroup.SoundType type : SoundGroup.SoundType.values()) {
|
||||||
|
if (type == SoundGroup.SoundType.CANCEL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> list = section
|
||||||
|
.getStringList(type.name().charAt(0) + type.name().substring(1).toLowerCase());
|
||||||
|
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String sound : list) {
|
||||||
|
if (!sound.matches(".+:.+")) {
|
||||||
|
DisguiseUtilities.getLogger()
|
||||||
|
.warning("Invalid sound '" + sound + "'! Must be a minecraft:sound.name");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
group.addSound(sound, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DisguiseUtilities.getLogger().info("Loaded sound group '" + key + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadSounds() {
|
||||||
|
DisguiseSoundEnums.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*private void loadSounds() {
|
||||||
|
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCODED_WITH_SOUNDS")) {
|
||||||
|
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (String line : lines) {
|
||||||
|
String[] groups = line.split("/");
|
||||||
|
|
||||||
|
SoundGroup group = new SoundGroup(groups[0]);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (SoundGroup.SoundType type : SoundGroup.SoundType.values()) {
|
||||||
|
String[] sounds = groups[++i].split(",");
|
||||||
|
|
||||||
|
for (String sound : sounds) {
|
||||||
|
group.addSound(sound, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException | NoClassDefFoundError e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package me.libraryaddict.disguise.utilities.watchers;
|
package me.libraryaddict.disguise.utilities.watchers;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.wrappers.MinecraftKey;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSoundEnums;
|
|
||||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
|
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
|
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.DisguiseSoundEnums;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Sound;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@ -32,21 +32,24 @@ public class CompileMethods {
|
|||||||
@CompileMethodsIntfer(user = "%%__USER__%%")
|
@CompileMethodsIntfer(user = "%%__USER__%%")
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
doMethods();
|
doMethods();
|
||||||
doSounds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doSounds() {
|
/*private static void doSounds() {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
|
|
||||||
for (DisguiseSoundEnums s : DisguiseSoundEnums.values()) {
|
for (DisguiseSoundEnums sound : DisguiseSoundEnums.values()){
|
||||||
StringBuilder sound = new StringBuilder(s.name());
|
|
||||||
|
|
||||||
for (DisguiseSound.SoundType type : DisguiseSound.SoundType.values()) {
|
}
|
||||||
sound.append(":");
|
|
||||||
|
for (Map.Entry<String, SoundGroup> entry : SoundGroup.getGroups().entrySet()) {
|
||||||
|
StringBuilder sound = new StringBuilder(entry.getKey());
|
||||||
|
|
||||||
|
for (SoundGroup.SoundType type : SoundGroup.SoundType.values()) {
|
||||||
|
sound.append("/");
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (Map.Entry<Sound, DisguiseSound.SoundType> values : s.getDisguiseSounds().entrySet()) {
|
for (Map.Entry<Object, SoundGroup.SoundType> values : entry.getValue().getDisguiseSounds().entrySet()) {
|
||||||
if (values.getValue() != type) {
|
if (values.getValue() != type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -55,7 +58,7 @@ public class CompileMethods {
|
|||||||
sound.append(",");
|
sound.append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
sound.append(values.getKey().name());
|
sound.append(MinecraftKey.fromHandle(values.getKey()).getFullKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +73,7 @@ public class CompileMethods {
|
|||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private static void addClass(ArrayList<Class> classes, Class c) {
|
private static void addClass(ArrayList<Class> classes, Class c) {
|
||||||
if (classes.contains(c)) {
|
if (classes.contains(c)) {
|
||||||
|
@ -6,6 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|||||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo;
|
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo;
|
||||||
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -47,6 +48,10 @@ public class DisguiseMethods {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DisguiseMethods() {
|
public DisguiseMethods() {
|
||||||
|
loadMethods();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadMethods() {
|
||||||
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
|
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
|
||||||
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
14
src/main/resources/sounds.yml
Normal file
14
src/main/resources/sounds.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Here you can define custom sounds for a sound group!
|
||||||
|
# This is an example group, this group will never be loaded.
|
||||||
|
# Create your sound group here, then use 'setSoundGroup <Name>' on your disguise
|
||||||
|
# You cannot use the same group name as a disguise type! So no 'PLAYER', 'COW' etc.
|
||||||
|
GroupName:
|
||||||
|
# If you don't set one of these options, or it is empty. Then no sound will be played for that sound type
|
||||||
|
Idle:
|
||||||
|
- minecraft:some.idle.sound
|
||||||
|
Hurt:
|
||||||
|
- minecraft:some.hurt.sound
|
||||||
|
Death:
|
||||||
|
- minecraft:some.death.scream.sound
|
||||||
|
Step:
|
||||||
|
- minecraft:some.step.sound
|
Loading…
Reference in New Issue
Block a user