2020-02-19 00:57:39 +01:00
|
|
|
package me.libraryaddict.disguise.utilities.watchers;
|
2020-02-13 07:47:02 +01:00
|
|
|
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
2020-02-13 22:06:49 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseSoundEnums;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
2020-02-19 00:57:39 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
|
2020-02-13 07:47:02 +01:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2020-02-13 22:06:49 +01:00
|
|
|
import org.bukkit.Sound;
|
2020-02-13 07:47:02 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.lang.reflect.Method;
|
2020-03-08 21:00:58 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Random;
|
2020-02-13 07:47:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by libraryaddict on 13/02/2020.
|
|
|
|
*/
|
|
|
|
public class CompileMethods {
|
|
|
|
public static void main(String[] args) {
|
2020-02-13 22:06:49 +01:00
|
|
|
doMethods();
|
|
|
|
doSounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void doSounds() {
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
|
|
|
for (DisguiseSoundEnums s : DisguiseSoundEnums.values()) {
|
|
|
|
StringBuilder sound = new StringBuilder(s.name());
|
|
|
|
|
|
|
|
for (DisguiseSound.SoundType type : DisguiseSound.SoundType.values()) {
|
|
|
|
sound.append(":");
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (Map.Entry<Sound, DisguiseSound.SoundType> values : s.getDisguiseSounds().entrySet()) {
|
|
|
|
if (values.getValue() != type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i++ > 0) {
|
|
|
|
sound.append(",");
|
|
|
|
}
|
|
|
|
|
|
|
|
sound.append(values.getKey().name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list.add(sound.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
File soundsFile = new File("target/classes/ANTI_PIRACY_ENCODED_WITH_SOUNDS");
|
|
|
|
|
|
|
|
try (PrintWriter writer = new PrintWriter(soundsFile, "UTF-8")) {
|
|
|
|
writer.write(StringUtils.join(list, "\n"));
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 11:56:34 +01:00
|
|
|
private static void addClass(ArrayList<Class> classes, Class c) {
|
|
|
|
if (classes.contains(c)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c != FlagWatcher.class) {
|
|
|
|
addClass(classes, c.getSuperclass());
|
|
|
|
}
|
2020-02-25 12:22:25 +01:00
|
|
|
|
|
|
|
classes.add(c);
|
2020-02-25 11:56:34 +01:00
|
|
|
}
|
|
|
|
|
2020-02-13 22:06:49 +01:00
|
|
|
private static void doMethods() {
|
2020-02-13 07:47:02 +01:00
|
|
|
ArrayList<Class<?>> classes = ClassGetter
|
|
|
|
.getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers");
|
|
|
|
|
2020-02-25 11:56:34 +01:00
|
|
|
ArrayList<Class> sorted = new ArrayList<>();
|
2020-02-13 07:47:02 +01:00
|
|
|
|
|
|
|
for (Class c : classes) {
|
2020-02-25 11:56:34 +01:00
|
|
|
addClass(sorted, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<String> methods = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Class c : sorted) {
|
2020-02-13 07:47:02 +01:00
|
|
|
for (Method method : c.getMethods()) {
|
2020-02-19 00:57:39 +01:00
|
|
|
if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) {
|
2020-02-13 07:47:02 +01:00
|
|
|
continue;
|
2020-02-19 00:57:39 +01:00
|
|
|
} else if (method.getParameterCount() > 1 && !method.isAnnotationPresent(NmsAddedIn.class) &&
|
2020-02-13 07:47:02 +01:00
|
|
|
!method.isAnnotationPresent(NmsRemovedIn.class)) {
|
|
|
|
continue;
|
2020-02-19 00:57:39 +01:00
|
|
|
} else if (!(method.getName().startsWith("set") && method.getParameterCount() == 1) &&
|
|
|
|
!method.getName().startsWith("get") && !method.getName().startsWith("has") &&
|
|
|
|
!method.getName().startsWith("is")) {
|
2020-02-13 07:47:02 +01:00
|
|
|
continue;
|
|
|
|
} else if (method.getName().equals("removePotionEffect")) {
|
|
|
|
continue;
|
2020-02-13 22:06:49 +01:00
|
|
|
} else if (LibsPremium.isPremium() && new Random().nextBoolean()) {
|
|
|
|
continue;
|
2020-02-13 07:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int added = -1;
|
|
|
|
int removed = -1;
|
|
|
|
|
|
|
|
if (method.isAnnotationPresent(NmsAddedIn.class)) {
|
|
|
|
added = method.getAnnotation(NmsAddedIn.class).val().ordinal();
|
|
|
|
} else if (method.getDeclaringClass().isAnnotationPresent(NmsAddedIn.class)) {
|
|
|
|
added = method.getDeclaringClass().getAnnotation(NmsAddedIn.class).val().ordinal();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (method.isAnnotationPresent(NmsRemovedIn.class)) {
|
|
|
|
removed = method.getAnnotation(NmsRemovedIn.class).val().ordinal();
|
|
|
|
} else if (method.getDeclaringClass().isAnnotationPresent(NmsRemovedIn.class)) {
|
|
|
|
removed = method.getDeclaringClass().getAnnotation(NmsRemovedIn.class).val().ordinal();
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:57:39 +01:00
|
|
|
String param = method.getParameterCount() == 1 ? method.getParameterTypes()[0].getName() : "";
|
|
|
|
String descriptor = "";
|
|
|
|
|
|
|
|
if (added >= 0 || removed >= 0) {
|
|
|
|
descriptor = ":" + getMethodDescriptor(method) + ":" + added + ":" + removed;
|
|
|
|
}
|
2020-02-13 07:47:02 +01:00
|
|
|
|
2020-02-19 00:57:39 +01:00
|
|
|
String s =
|
|
|
|
method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" + param + descriptor;
|
2020-02-13 07:47:02 +01:00
|
|
|
|
|
|
|
if (methods.contains(s)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
methods.add(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 22:06:49 +01:00
|
|
|
File methodsFile = new File("target/classes/ANTI_PIRACY_ENCRYPTION");
|
2020-02-13 07:47:02 +01:00
|
|
|
|
|
|
|
try (PrintWriter writer = new PrintWriter(methodsFile, "UTF-8")) {
|
|
|
|
writer.write(StringUtils.join(methods, "\n"));
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 00:57:39 +01:00
|
|
|
|
|
|
|
static String getDescriptorForClass(final Class c) {
|
|
|
|
if (c.isPrimitive()) {
|
|
|
|
if (c == byte.class)
|
|
|
|
return "B";
|
|
|
|
if (c == char.class)
|
|
|
|
return "C";
|
|
|
|
if (c == double.class)
|
|
|
|
return "D";
|
|
|
|
if (c == float.class)
|
|
|
|
return "F";
|
|
|
|
if (c == int.class)
|
|
|
|
return "I";
|
|
|
|
if (c == long.class)
|
|
|
|
return "J";
|
|
|
|
if (c == short.class)
|
|
|
|
return "S";
|
|
|
|
if (c == boolean.class)
|
|
|
|
return "Z";
|
|
|
|
if (c == void.class)
|
|
|
|
return "V";
|
|
|
|
|
|
|
|
throw new RuntimeException("Unrecognized primitive " + c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.isArray())
|
|
|
|
return c.getName().replace('.', '/');
|
|
|
|
|
|
|
|
return ('L' + c.getName() + ';').replace('.', '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
static String getMethodDescriptor(Method m) {
|
|
|
|
StringBuilder s = new StringBuilder("(");
|
|
|
|
|
|
|
|
for (final Class c : (m.getParameterTypes())) {
|
|
|
|
s.append(getDescriptorForClass(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.append(")") + getDescriptorForClass(m.getReturnType());
|
|
|
|
}
|
2020-02-13 07:47:02 +01:00
|
|
|
}
|