Add 1.12 support
This commit is contained in:
@@ -2,18 +2,67 @@ package me.libraryaddict.disguise.utilities.reflection;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.MushroomCowWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseSoundEnums;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 13/02/2020.
|
||||
*/
|
||||
public class CompileMethods {
|
||||
public static void main(String[] args) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private static void doMethods() {
|
||||
ArrayList<Class<?>> classes = ClassGetter
|
||||
.getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers");
|
||||
classes.add(FlagWatcher.class);
|
||||
@@ -36,6 +85,8 @@ public class CompileMethods {
|
||||
continue;
|
||||
} else if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) {
|
||||
continue;
|
||||
} else if (LibsPremium.isPremium() && new Random().nextBoolean()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int added = -1;
|
||||
@@ -56,8 +107,7 @@ public class CompileMethods {
|
||||
Class<?> param = method.getParameterTypes()[0];
|
||||
|
||||
String s = ((added >= 0 || removed >= 0) ? added + ":" + removed + ":" : "") +
|
||||
method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" +
|
||||
param.getName();
|
||||
method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" + param.getName();
|
||||
|
||||
if (methods.contains(s)) {
|
||||
continue;
|
||||
@@ -67,7 +117,7 @@ public class CompileMethods {
|
||||
}
|
||||
}
|
||||
|
||||
File methodsFile = new File("target/classes/methods.txt");
|
||||
File methodsFile = new File("target/classes/ANTI_PIRACY_ENCRYPTION");
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(methodsFile, "UTF-8")) {
|
||||
writer.write(StringUtils.join(methods, "\n"));
|
||||
|
@@ -36,7 +36,7 @@ public class DisguiseMethods {
|
||||
}
|
||||
|
||||
public DisguiseMethods() {
|
||||
try (InputStream stream = LibsDisguises.getInstance().getResource("methods.txt")) {
|
||||
try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) {
|
||||
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||
.collect(Collectors.toList());
|
||||
HashMap<String, Class<? extends FlagWatcher>> classes = new HashMap<>();
|
||||
|
@@ -4,6 +4,7 @@ package me.libraryaddict.disguise.utilities.reflection;
|
||||
* Created by libraryaddict on 6/02/2020.
|
||||
*/
|
||||
public enum NmsVersion {
|
||||
v1_12,
|
||||
v1_13,
|
||||
v1_14,
|
||||
v1_15;
|
||||
|
@@ -978,7 +978,7 @@ public class ReflectionManager {
|
||||
Optional opt = (Optional) value;
|
||||
|
||||
if (!opt.isPresent())
|
||||
return value;
|
||||
return NmsVersion.v1_13.isSupported() ? value : com.google.common.base.Optional.absent();
|
||||
|
||||
Object val = opt.get();
|
||||
|
||||
@@ -986,15 +986,18 @@ public class ReflectionManager {
|
||||
BlockPosition pos = (BlockPosition) val;
|
||||
|
||||
try {
|
||||
return Optional.of(getNmsConstructor("BlockPosition", int.class, int.class, int.class)
|
||||
.newInstance(pos.getX(), pos.getY(), pos.getZ()));
|
||||
Object obj = getNmsConstructor("BlockPosition", int.class, int.class, int.class)
|
||||
.newInstance(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
||||
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else if (val instanceof WrappedBlockData) {
|
||||
try {
|
||||
return Optional.of(((WrappedBlockData) val).getHandle());
|
||||
Object obj = ((WrappedBlockData) val).getHandle();
|
||||
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -1003,11 +1006,15 @@ public class ReflectionManager {
|
||||
val = getNmsItem((ItemStack) val);
|
||||
|
||||
if (val == null)
|
||||
return Optional.empty();
|
||||
return NmsVersion.v1_13.isSupported() ? Optional.empty() : com.google.common.base.Optional.absent();
|
||||
else
|
||||
return Optional.of(val);
|
||||
} else if (val instanceof WrappedChatComponent) {
|
||||
return Optional.of(((WrappedChatComponent) val).getHandle());
|
||||
Object obj = ((WrappedChatComponent) val).getHandle();
|
||||
|
||||
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
|
||||
}else if (!NmsVersion.v1_13.isSupported()) {
|
||||
return com.google.common.base.Optional.of(val);
|
||||
}
|
||||
} else if (value instanceof Vector3F) {
|
||||
Vector3F angle = (Vector3F) value;
|
||||
@@ -1209,13 +1216,17 @@ public class ReflectionManager {
|
||||
|
||||
public static int getEntityTypeId(EntityType entityType) {
|
||||
try {
|
||||
Object entityTypes = getEntityType(entityType);
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
Object entityTypes = getEntityType(entityType);
|
||||
|
||||
Class typesClass = getNmsClass("IRegistry");
|
||||
Class typesClass = getNmsClass("IRegistry");
|
||||
|
||||
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
||||
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
||||
|
||||
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
|
||||
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
|
||||
}
|
||||
|
||||
return entityType.getTypeId();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
Reference in New Issue
Block a user