Fix sounds broken on non-1.15 versions

This commit is contained in:
libraryaddict 2020-05-24 01:44:19 +12:00
parent 37e7a0bac7
commit 567f278131
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
6 changed files with 52 additions and 31 deletions

View File

@ -1283,6 +1283,18 @@ public class ReflectionManager {
return null;
}
public static Object createSoundEffect(String minecraftKey) {
try {
return getNmsConstructor("SoundEffect", getNmsClass("MinecraftKey"))
.newInstance(createMinecraftKey(minecraftKey));
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Object createMinecraftKey(String name) {
try {
return getNmsClass("MinecraftKey").getConstructor(String.class).newInstance(name);

View File

@ -2,13 +2,11 @@ package me.libraryaddict.disguise.utilities.sounds;
import lombok.Getter;
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 java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.HashMap;
/**
* Only living disguises go in here!
@ -231,10 +229,14 @@ public enum DisguiseSoundEnums {
Sound.ENTITY_ZOMBIE_VILLAGER_DEATH, Sound.ENTITY_ZOMBIE_VILLAGER_AMBIENT, Sound.ENTITY_ZOMBIE_INFECT,
Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
private SoundGroup group = new SoundGroup(name());
@Getter
private HashMap<Sound, SoundType> sounds = new HashMap<>();
DisguiseSoundEnums(Object hurt, Object step, Object death, Object idle, Object... sounds) {
if (LibsDisguises.getInstance() != null) {
throw new IllegalStateException("This cannot be called on a running server");
}
addSound(hurt, SoundType.HURT);
addSound(step, SoundType.STEP);
addSound(death, SoundType.DEATH);
@ -266,6 +268,6 @@ public enum DisguiseSoundEnums {
}
private void addSound(Sound sound, SoundType type) {
group.addSound(ReflectionManager.getCraftSound(sound), type);
sounds.put(sound, type);
}
}

View File

@ -2,7 +2,6 @@ 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;
@ -33,8 +32,12 @@ public class SoundGroup {
}
public void addSound(Object sound, SoundType type) {
if (sound instanceof String) {
sound = ReflectionManager.createMinecraftKey((String) sound);
if (sound instanceof Sound) {
sound = ReflectionManager.getCraftSound((Sound) sound);
} else if (sound instanceof String) {
sound = ReflectionManager.createSoundEffect((String) sound);
} else if (!sound.getClass().getName().equals("SoundEffect")) {
throw new IllegalArgumentException();
}
disguiseSounds.put(sound, type);

View File

@ -2,7 +2,7 @@ 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.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@ -70,25 +70,33 @@ public class SoundManager {
}
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("/");
String[] groups = line.split("/", -1);
SoundGroup group = new SoundGroup(groups[0]);
int i = 0;
for (SoundGroup.SoundType type : SoundGroup.SoundType.values()) {
String[] sounds = groups[++i].split(",");
String s = groups[++i];
if (s.isEmpty()) {
continue;
}
String[] sounds = s.split(",");
for (String sound : sounds) {
group.addSound(sound, type);
try {
Sound actualSound = Sound.valueOf(sound);
group.addSound(actualSound, type);
}
catch (Exception ignored) {
}
}
}
}
@ -96,5 +104,5 @@ public class SoundManager {
catch (IOException | NoClassDefFoundError e) {
e.printStackTrace();
}
}*/
}
}

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.utilities.watchers;
import com.comphenix.protocol.wrappers.MinecraftKey;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
@ -9,6 +8,7 @@ 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.bukkit.Sound;
import java.io.File;
import java.io.PrintWriter;
@ -32,25 +32,22 @@ public class CompileMethods {
@CompileMethodsIntfer(user = "%%__USER__%%")
public static void main(String[] args) {
doMethods();
doSounds();
}
/*private static void doSounds() {
private static void doSounds() {
List<String> list = new ArrayList<>();
for (DisguiseSoundEnums sound : DisguiseSoundEnums.values()){
}
for (Map.Entry<String, SoundGroup> entry : SoundGroup.getGroups().entrySet()) {
StringBuilder sound = new StringBuilder(entry.getKey());
for (DisguiseSoundEnums e : DisguiseSoundEnums.values()) {
StringBuilder sound = new StringBuilder(e.name());
for (SoundGroup.SoundType type : SoundGroup.SoundType.values()) {
sound.append("/");
int i = 0;
for (Map.Entry<Object, SoundGroup.SoundType> values : entry.getValue().getDisguiseSounds().entrySet()) {
if (values.getValue() != type) {
for (Map.Entry<Sound, SoundGroup.SoundType> entry : e.getSounds().entrySet()) {
if (entry.getValue() != type) {
continue;
}
@ -58,7 +55,7 @@ public class CompileMethods {
sound.append(",");
}
sound.append(MinecraftKey.fromHandle(values.getKey()).getFullKey());
sound.append(entry.getKey().name());
}
}
@ -73,7 +70,7 @@ public class CompileMethods {
catch (Exception ex) {
ex.printStackTrace();
}
}*/
}
private static void addClass(ArrayList<Class> classes, Class c) {
if (classes.contains(c)) {

View File

@ -6,7 +6,6 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo;
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
import java.io.BufferedReader;
import java.io.IOException;