delete VersionUtil in favor of PacketEvents api
This commit is contained in:
parent
aff202e5ec
commit
4a3a54f2b8
6 changed files with 22 additions and 43 deletions
|
@ -1,11 +1,12 @@
|
||||||
package lol.pyr.znpcsplus.entity;
|
package lol.pyr.znpcsplus.entity;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
|
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||||
import lol.pyr.znpcsplus.reflection.Reflections;
|
|
||||||
import lol.pyr.znpcsplus.util.VersionUtil;
|
|
||||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||||
import lol.pyr.znpcsplus.packets.PacketFactory;
|
import lol.pyr.znpcsplus.packets.PacketFactory;
|
||||||
|
import lol.pyr.znpcsplus.reflection.Reflections;
|
||||||
import lol.pyr.znpcsplus.util.ZLocation;
|
import lol.pyr.znpcsplus.util.ZLocation;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -71,8 +72,9 @@ public class PacketEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int reserveEntityID() {
|
private static int reserveEntityID() {
|
||||||
if (VersionUtil.isNewerThan(14)) return Reflections.ATOMIC_ENTITY_ID_FIELD.get().incrementAndGet();
|
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) {
|
||||||
else {
|
return Reflections.ATOMIC_ENTITY_ID_FIELD.get().incrementAndGet();
|
||||||
|
} else {
|
||||||
int id = Reflections.ENTITY_ID_MODIFIER.get();
|
int id = Reflections.ENTITY_ID_MODIFIER.get();
|
||||||
Reflections.ENTITY_ID_MODIFIER.set(id + 1);
|
Reflections.ENTITY_ID_MODIFIER.set(id + 1);
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package lol.pyr.znpcsplus.reflection;
|
package lol.pyr.znpcsplus.reflection;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
|
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import lol.pyr.znpcsplus.reflection.types.ClassReflection;
|
import lol.pyr.znpcsplus.reflection.types.ClassReflection;
|
||||||
import lol.pyr.znpcsplus.reflection.types.FieldReflection;
|
import lol.pyr.znpcsplus.reflection.types.FieldReflection;
|
||||||
import lol.pyr.znpcsplus.reflection.types.MethodReflection;
|
import lol.pyr.znpcsplus.reflection.types.MethodReflection;
|
||||||
import lol.pyr.znpcsplus.util.VersionUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public class ReflectionBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReflectionBuilder withClassName(String className) {
|
public ReflectionBuilder withClassName(String className) {
|
||||||
this.className.add(ReflectionPackage.joinWithDot(reflectionPackage, VersionUtil.isNewerThan(17) ? additionalData : "", className));
|
this.className.add(ReflectionPackage.joinWithDot(reflectionPackage, PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_17) ? additionalData : "", className));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package lol.pyr.znpcsplus.reflection;
|
package lol.pyr.znpcsplus.reflection;
|
||||||
|
|
||||||
import lol.pyr.znpcsplus.util.VersionUtil;
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -39,7 +39,7 @@ public abstract class ReflectionLazyLoader<T> {
|
||||||
logger.warning(getClass().getSimpleName() + " failed!");
|
logger.warning(getClass().getSimpleName() + " failed!");
|
||||||
logger.warning("Class Names: " + possibleClassNames);
|
logger.warning("Class Names: " + possibleClassNames);
|
||||||
logger.warning("Reflection Type: " + getClass().getCanonicalName());
|
logger.warning("Reflection Type: " + getClass().getCanonicalName());
|
||||||
logger.warning("Bukkit Version: " + VersionUtil.BUKKIT_VERSION + " (" + VersionUtil.getBukkitPackage() + ")");
|
logger.warning("Server Version: " + PacketEvents.getAPI().getServerManager().getVersion().name());
|
||||||
printDebugInfo(logger::warning);
|
printDebugInfo(logger::warning);
|
||||||
logger.warning("Exception:");
|
logger.warning("Exception:");
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package lol.pyr.znpcsplus.reflection;
|
package lol.pyr.znpcsplus.reflection;
|
||||||
|
|
||||||
import lol.pyr.znpcsplus.util.VersionUtil;
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
|
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -12,14 +14,15 @@ import java.util.stream.Collectors;
|
||||||
* pre-1.17 had all of their classes "flattened" into one package.
|
* pre-1.17 had all of their classes "flattened" into one package.
|
||||||
*/
|
*/
|
||||||
public class ReflectionPackage {
|
public class ReflectionPackage {
|
||||||
private static final boolean flattened = !VersionUtil.isNewerThan(17);
|
private static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||||
public static final String BUKKIT = "org.bukkit.craftbukkit." + VersionUtil.getBukkitPackage();
|
public static final String BUKKIT = "org.bukkit.craftbukkit." + VERSION;
|
||||||
|
private static final boolean flattened = !PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_17);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the classes are flattened, if so we need to add the version string into the
|
* Check if the classes are flattened, if so we need to add the version string into the
|
||||||
* package string which is another quirk of the old server jars.
|
* package string which is another quirk of the old server jars.
|
||||||
*/
|
*/
|
||||||
public static final String MINECRAFT = joinWithDot("net.minecraft", flattened ? "server." + VersionUtil.getBukkitPackage() : "");
|
public static final String MINECRAFT = joinWithDot("net.minecraft", flattened ? "server." + VERSION : "");
|
||||||
public static final String ENTITY = flattened ? MINECRAFT : joinWithDot(MINECRAFT, "world.entity");
|
public static final String ENTITY = flattened ? MINECRAFT : joinWithDot(MINECRAFT, "world.entity");
|
||||||
|
|
||||||
public static String joinWithDot(String... parts) {
|
public static String joinWithDot(String... parts) {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package lol.pyr.znpcsplus.reflection;
|
package lol.pyr.znpcsplus.reflection;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
|
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import lol.pyr.znpcsplus.reflection.types.FieldReflection;
|
import lol.pyr.znpcsplus.reflection.types.FieldReflection;
|
||||||
import lol.pyr.znpcsplus.util.FoliaUtil;
|
import lol.pyr.znpcsplus.util.FoliaUtil;
|
||||||
import lol.pyr.znpcsplus.util.VersionUtil;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
@ -46,7 +47,7 @@ public final class Reflections {
|
||||||
new ReflectionBuilder(ReflectionPackage.ENTITY)
|
new ReflectionBuilder(ReflectionPackage.ENTITY)
|
||||||
.withClassName(ENTITY_CLASS)
|
.withClassName(ENTITY_CLASS)
|
||||||
.withFieldName("entityCount")
|
.withFieldName("entityCount")
|
||||||
.setStrict(!VersionUtil.isNewerThan(14))
|
.setStrict(!PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14))
|
||||||
.toFieldReflection()
|
.toFieldReflection()
|
||||||
.toStaticValueModifier(int.class);
|
.toStaticValueModifier(int.class);
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public final class Reflections {
|
||||||
.withFieldName("d")
|
.withFieldName("d")
|
||||||
.withFieldName("c")
|
.withFieldName("c")
|
||||||
.withExpectResult(AtomicInteger.class)
|
.withExpectResult(AtomicInteger.class)
|
||||||
.setStrict(VersionUtil.isNewerThan(14))
|
.setStrict(PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14))
|
||||||
.toFieldReflection()
|
.toFieldReflection()
|
||||||
.toStaticValueLoader(AtomicInteger.class);
|
.toStaticValueLoader(AtomicInteger.class);
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package lol.pyr.znpcsplus.util;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
public final class VersionUtil {
|
|
||||||
public static final int BUKKIT_VERSION;
|
|
||||||
|
|
||||||
static {
|
|
||||||
int version = 0;
|
|
||||||
try {
|
|
||||||
version = Integer.parseInt(getFormattedBukkitPackage());
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
BUKKIT_VERSION = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNewerThan(int version) {
|
|
||||||
return (BUKKIT_VERSION >= version);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBukkitPackage() {
|
|
||||||
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getFormattedBukkitPackage() {
|
|
||||||
String version = getBukkitPackage().replace("v", "").replace("R", "");
|
|
||||||
return version.substring(2, version.length() - 2);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue