From 20dd0055188bc34c01859821ba91b816ced2d2e3 Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Wed, 14 Aug 2024 11:40:24 -0400 Subject: [PATCH 1/7] remove usages of bukkit scheduler --- .../build.gradle.kts | 6 ++++ build.gradle.kts | 8 +++++ .../com/cjcrafter/vivecraft/Reflector.java | 33 ++++++++++++------- .../java/com/cjcrafter/vivecraft/VSE.java | 16 ++++----- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/BuildVivecraftSpigotExtensions/build.gradle.kts b/BuildVivecraftSpigotExtensions/build.gradle.kts index 80d0b56..0bc3e93 100644 --- a/BuildVivecraftSpigotExtensions/build.gradle.kts +++ b/BuildVivecraftSpigotExtensions/build.gradle.kts @@ -19,6 +19,8 @@ bukkit { prefix = "Vivecraft" softDepend = listOf("Vault") + foliaSupported = true + commands { register("Vive") { description = "Vivecraft Spigot Extensions" @@ -87,5 +89,9 @@ tasks.shadowJar { relocate("com.cryptomorin.xseries", "com.cjcrafter.vivecraft.xseries") { include(dependency("com.github.cryptomorin:XSeries:")) } + + relocate("com.cjcrafter.foliascheduler", "com.cjcrafter.vivecraft.foliascheduler") { + include(dependency("com.cjcrafter:foliascheduler:")) + } } } diff --git a/build.gradle.kts b/build.gradle.kts index 8cc2c93..bb7a616 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,9 +15,17 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") + compileOnly("org.jetbrains:annotations:24.1.0") + + // soft depend compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") + + // We shade these implementation("com.github.cryptomorin:XSeries:11.1.0") + implementation("com.cjcrafter:foliascheduler:0.4.5") implementation("org.bstats:bstats-bukkit:3.0.1") + implementation("xyz.jpenilla:reflection-remapper:0.1.1") // for paper auto remapping + implementation("net.fabricmc:mapping-io:0.5.0") // for paper auto remapping } java { diff --git a/src/main/java/com/cjcrafter/vivecraft/Reflector.java b/src/main/java/com/cjcrafter/vivecraft/Reflector.java index 2299c5e..3b82ef9 100644 --- a/src/main/java/com/cjcrafter/vivecraft/Reflector.java +++ b/src/main/java/com/cjcrafter/vivecraft/Reflector.java @@ -1,6 +1,10 @@ package com.cjcrafter.vivecraft; +import com.cjcrafter.foliascheduler.MinecraftVersions; +import com.cjcrafter.foliascheduler.ServerVersions; import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; +import xyz.jpenilla.reflectionremapper.ReflectionRemapper; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -11,32 +15,39 @@ public final class Reflector { private static final String nmsVersion; - private static final int mcVersion; static { String versionString = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; nmsVersion = "net.minecraft.server." + versionString + '.'; - mcVersion = Integer.parseInt(versionString.split("_")[1]); } /** - * Returns the NMS class with the given name. - * In mc versions 1.17 and higher, pack is used for the - * package the class is in. Previous versions ignore pack. + * Returns the NMS class with the given name. In mc versions 1.17 and higher, pack is + * used for the package the class is in. Previous versions ignore pack. * - * @param pack The non-null package name that contains the class defined - * by name. Make sure the string ends with a dot. + *

+ * On paper servers in MC 1.20.5 and higher, packages have been remapped. We have to use the + * remapping tool to get the correct package name and class name. + * + * @param pack The non-null package name that contains the class defined by name. Make + * sure the string ends with a dot. * @param name The non-null name of the class to find. * @return The NMS class with that name. */ - public static Class getNMSClass(String pack, String name) { + public static Class getNMSClass(@NotNull String pack, @NotNull String name) { String className; - if (mcVersion < 17) - className = nmsVersion + name; - else + if (MinecraftVersions.CAVES_AND_CLIFFS_1.isAtLeast()) { className = "net.minecraft." + pack + '.' + name; + if (ServerVersions.isPaper() && MinecraftVersions.TRAILS_AND_TAILS.get(5).isAtLeast()) { + ReflectionRemapper remapper = ReflectionRemapper.forReobfMappingsInPaperJar(); + className = remapper.remapClassOrArrayName(className); + } + } else { + className = nmsVersion + name; + } + try { return Class.forName(className); } catch (ClassNotFoundException e) { diff --git a/src/main/java/com/cjcrafter/vivecraft/VSE.java b/src/main/java/com/cjcrafter/vivecraft/VSE.java index 82f45cc..e02d36d 100644 --- a/src/main/java/com/cjcrafter/vivecraft/VSE.java +++ b/src/main/java/com/cjcrafter/vivecraft/VSE.java @@ -1,5 +1,8 @@ package com.cjcrafter.vivecraft; +import com.cjcrafter.foliascheduler.FoliaCompatibility; +import com.cjcrafter.foliascheduler.ServerImplementation; +import com.cjcrafter.foliascheduler.TaskImplementation; import net.milkbowl.vault.permission.Permission; import org.bstats.bukkit.Metrics; import org.bstats.charts.AdvancedPie; @@ -40,7 +43,8 @@ public class VSE extends JavaPlugin implements Listener { public boolean debug = false; public boolean vault; FileConfiguration config = getConfig(); - private int sendPosDataTask = 0; + private ServerImplementation scheduler; + private TaskImplementation sendPosDataTask; public static boolean isVive(Player p) { if (p == null) return false; @@ -77,6 +81,7 @@ public static boolean isStanding(Player player) { public void onEnable() { super.onEnable(); me = this; + scheduler = new FoliaCompatibility(this).getServerImplementation(); if (getConfig().getBoolean("general.vive-crafting", true)) { { @@ -166,12 +171,7 @@ public Map call() throws Exception { debug = (getConfig().getBoolean("general.debug", false)); - sendPosDataTask = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { - public void run() { - sendPosData(); - } - }, 20, 1); - + sendPosDataTask = scheduler.async().runAtFixedRate(this::sendPosData, 20L, 1L); CheckAllEntities(); @@ -241,7 +241,7 @@ public void sendPosData() { @Override public void onDisable() { - getServer().getScheduler().cancelTask(sendPosDataTask); + sendPosDataTask.cancel(); super.onDisable(); } From 9d1e6cd82f5e64a584b57081720839c598751b23 Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Thu, 3 Oct 2024 12:40:49 -0400 Subject: [PATCH 2/7] switch to good folia lib --- .../build.gradle.kts | 4 +- .../Vivecraft_1_19_R3/build.gradle.kts | 1 + .../compatibility/Vivecraft_v1_19_R3.java | 32 +-- .../Vivecraft_1_20_R1/build.gradle.kts | 1 + .../compatibility/Vivecraft_v1_20_R1.java | 23 +- .../Vivecraft_1_20_R2/build.gradle.kts | 1 + .../compatibility/Vivecraft_v1_20_R2.java | 23 +- .../Vivecraft_1_20_R3/build.gradle.kts | 1 + .../compatibility/Vivecraft_v1_20_R3.java | 23 +- .../Vivecraft_1_20_R4/build.gradle.kts | 1 + .../compatibility/Vivecraft_v1_20_R4.java | 23 +- .../Vivecraft_1_21_R1/build.gradle.kts | 5 +- .../compatibility/Vivecraft_v1_21_R1.java | 23 +- build.gradle.kts | 4 +- .../com/cjcrafter/vivecraft/Reflector.java | 219 ------------------ 15 files changed, 88 insertions(+), 296 deletions(-) delete mode 100644 src/main/java/com/cjcrafter/vivecraft/Reflector.java diff --git a/BuildVivecraftSpigotExtensions/build.gradle.kts b/BuildVivecraftSpigotExtensions/build.gradle.kts index 0bc3e93..634fbb1 100644 --- a/BuildVivecraftSpigotExtensions/build.gradle.kts +++ b/BuildVivecraftSpigotExtensions/build.gradle.kts @@ -1,7 +1,7 @@ import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask group = "com.cjcrafter" -version = "3.0.1" +version = "3.1.0" plugins { `java-library` @@ -64,7 +64,7 @@ repositories { dependencies { implementation(project(":")) // base project - listOf("19_R3", "20_R1", "20_R2", "20_R3").forEach { + listOf("19_R3", "20_R1", "20_R2", "20_R3", "20_R4", "21_R1").forEach { implementation(project(":Vivecraft_1_$it", "reobf")) } } diff --git a/Compatibility/Vivecraft_1_19_R3/build.gradle.kts b/Compatibility/Vivecraft_1_19_R3/build.gradle.kts index 1d65868..76b6a28 100644 --- a/Compatibility/Vivecraft_1_19_R3/build.gradle.kts +++ b/Compatibility/Vivecraft_1_19_R3/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") implementation(project(":")) compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT") + compileOnly("com.cjcrafter:foliascheduler:0.5.0") } java { diff --git a/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java b/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java index 1213c67..f713e8e 100644 --- a/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java +++ b/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java @@ -1,5 +1,8 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.MethodInvoker; +import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; @@ -40,7 +43,6 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.cjcrafter.vivecraft.Reflector; import com.cjcrafter.vivecraft.VSE; import com.cjcrafter.vivecraft.VivePlayer; @@ -51,23 +53,23 @@ public class Vivecraft_v1_19_R3 implements VivecraftCompatibility { private static Class classEndermanFreezeWhenLookedAt; private static Class classEndermanLookForPlayerGoal; - private static Reflector.FieldAccessor poseAccessor; - private static Reflector.FieldAccessor itemsByIdAccessor; - private static Reflector.FieldAccessor eyeHeightAccessor; - private static Reflector.FieldAccessor fallFlyTicksAccessor; - private static Reflector.MethodAccessor teleportAccessor; - private static Reflector.MethodAccessor teleportTowardsAccessor; + private static FieldAccessor poseAccessor; + private static FieldAccessor itemsByIdAccessor; + private static FieldAccessor eyeHeightAccessor; + private static FieldAccessor fallFlyTicksAccessor; + private static MethodInvoker teleportAccessor; + private static MethodInvoker teleportTowardsAccessor; public Vivecraft_v1_19_R3() { - classEndermanFreezeWhenLookedAt = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$a"); - classEndermanLookForPlayerGoal = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = Reflector.getField(Entity.class, EntityDataAccessor.class, 6, false); - itemsByIdAccessor = Reflector.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = Reflector.getField(Entity.class, "bf"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = Reflector.getField(LivingEntity.class, "bw"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/LivingEntity.html - teleportAccessor = Reflector.getMethod(EnderMan.class, "w"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/monster/EnderMan.html - teleportTowardsAccessor = Reflector.getMethod(Enderman.class, "a", Entity.class); + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); + classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bf"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/Entity.html + fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bw"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/LivingEntity.html + teleportAccessor = ReflectionUtil.getMethod(EnderMan.class, "w"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/monster/EnderMan.html + teleportTowardsAccessor = ReflectionUtil.getMethod(Enderman.class, "a", Entity.class); } @Override diff --git a/Compatibility/Vivecraft_1_20_R1/build.gradle.kts b/Compatibility/Vivecraft_1_20_R1/build.gradle.kts index e0af033..79fd5e8 100644 --- a/Compatibility/Vivecraft_1_20_R1/build.gradle.kts +++ b/Compatibility/Vivecraft_1_20_R1/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") implementation(project(":")) compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") + compileOnly("com.cjcrafter:foliascheduler:0.5.0") } java { diff --git a/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java b/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java index 31590c3..d630348 100644 --- a/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java +++ b/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java @@ -1,5 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; @@ -40,7 +42,6 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.cjcrafter.vivecraft.Reflector; import com.cjcrafter.vivecraft.VSE; import com.cjcrafter.vivecraft.VivePlayer; @@ -51,19 +52,19 @@ public class Vivecraft_v1_20_R1 implements VivecraftCompatibility { private static Class classEndermanFreezeWhenLookedAt; private static Class classEndermanLookForPlayerGoal; - private static Reflector.FieldAccessor poseAccessor; - private static Reflector.FieldAccessor itemsByIdAccessor; - private static Reflector.FieldAccessor eyeHeightAccessor; - private static Reflector.FieldAccessor fallFlyTicksAccessor; + private static FieldAccessor poseAccessor; + private static FieldAccessor itemsByIdAccessor; + private static FieldAccessor eyeHeightAccessor; + private static FieldAccessor fallFlyTicksAccessor; public Vivecraft_v1_20_R1() { - classEndermanFreezeWhenLookedAt = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/monster/EnderMan.html - classEndermanLookForPlayerGoal = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = Reflector.getField(Entity.class, EntityDataAccessor.class, 6, false); - itemsByIdAccessor = Reflector.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = Reflector.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = Reflector.getField(LivingEntity.class, "by"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/LivingEntity.html + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/monster/EnderMan.html + classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/Entity.html + fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "by"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/LivingEntity.html } @Override diff --git a/Compatibility/Vivecraft_1_20_R2/build.gradle.kts b/Compatibility/Vivecraft_1_20_R2/build.gradle.kts index e822a43..00752a9 100644 --- a/Compatibility/Vivecraft_1_20_R2/build.gradle.kts +++ b/Compatibility/Vivecraft_1_20_R2/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") implementation(project(":")) compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") + compileOnly("com.cjcrafter:foliascheduler:0.5.0") } java { diff --git a/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java b/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java index a3f579e..3705bae 100644 --- a/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java +++ b/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java @@ -1,5 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; @@ -40,7 +42,6 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.cjcrafter.vivecraft.Reflector; import com.cjcrafter.vivecraft.VSE; import com.cjcrafter.vivecraft.VivePlayer; @@ -51,19 +52,19 @@ public class Vivecraft_v1_20_R2 implements VivecraftCompatibility { private static Class classEndermanFreezeWhenLookedAt; private static Class classEndermanLookForPlayerGoal; - private static Reflector.FieldAccessor poseAccessor; - private static Reflector.FieldAccessor itemsByIdAccessor; - private static Reflector.FieldAccessor eyeHeightAccessor; - private static Reflector.FieldAccessor fallFlyTicksAccessor; + private static FieldAccessor poseAccessor; + private static FieldAccessor itemsByIdAccessor; + private static FieldAccessor eyeHeightAccessor; + private static FieldAccessor fallFlyTicksAccessor; public Vivecraft_v1_20_R2() { - classEndermanFreezeWhenLookedAt = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html - classEndermanLookForPlayerGoal = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = Reflector.getField(Entity.class, EntityDataAccessor.class, 6, false); - itemsByIdAccessor = Reflector.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = Reflector.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = Reflector.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html + classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html + fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html } @Override diff --git a/Compatibility/Vivecraft_1_20_R3/build.gradle.kts b/Compatibility/Vivecraft_1_20_R3/build.gradle.kts index 5ef37e1..762b4ab 100644 --- a/Compatibility/Vivecraft_1_20_R3/build.gradle.kts +++ b/Compatibility/Vivecraft_1_20_R3/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { paperweight.paperDevBundle("1.20.3-R0.1-SNAPSHOT") implementation(project(":")) compileOnly("org.spigotmc:spigot-api:1.20.3-R0.1-SNAPSHOT") + compileOnly("com.cjcrafter:foliascheduler:0.5.0") } java { diff --git a/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java b/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java index 77b94a8..722110f 100644 --- a/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java +++ b/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java @@ -1,5 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; @@ -40,7 +42,6 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.cjcrafter.vivecraft.Reflector; import com.cjcrafter.vivecraft.VSE; import com.cjcrafter.vivecraft.VivePlayer; @@ -51,19 +52,19 @@ public class Vivecraft_v1_20_R3 implements VivecraftCompatibility { private static Class classEndermanFreezeWhenLookedAt; private static Class classEndermanLookForPlayerGoal; - private static Reflector.FieldAccessor poseAccessor; - private static Reflector.FieldAccessor itemsByIdAccessor; - private static Reflector.FieldAccessor eyeHeightAccessor; - private static Reflector.FieldAccessor fallFlyTicksAccessor; + private static FieldAccessor poseAccessor; + private static FieldAccessor itemsByIdAccessor; + private static FieldAccessor eyeHeightAccessor; + private static FieldAccessor fallFlyTicksAccessor; public Vivecraft_v1_20_R3() { - classEndermanFreezeWhenLookedAt = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html - classEndermanLookForPlayerGoal = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = Reflector.getField(Entity.class, EntityDataAccessor.class, 6, false); - itemsByIdAccessor = Reflector.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = Reflector.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = Reflector.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html + classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html + fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html } @Override diff --git a/Compatibility/Vivecraft_1_20_R4/build.gradle.kts b/Compatibility/Vivecraft_1_20_R4/build.gradle.kts index 26671ed..c951d91 100644 --- a/Compatibility/Vivecraft_1_20_R4/build.gradle.kts +++ b/Compatibility/Vivecraft_1_20_R4/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") implementation(project(":")) compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") + compileOnly("com.cjcrafter:foliascheduler:0.5.0") } java { diff --git a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java index 23fa681..e4cebd4 100644 --- a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java +++ b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java @@ -1,5 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; @@ -41,7 +43,6 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.cjcrafter.vivecraft.Reflector; import com.cjcrafter.vivecraft.VSE; import com.cjcrafter.vivecraft.VivePlayer; @@ -52,19 +53,19 @@ public class Vivecraft_v1_20_R4 implements VivecraftCompatibility { private static Class classEndermanFreezeWhenLookedAt; private static Class classEndermanLookForPlayerGoal; - private static Reflector.FieldAccessor poseAccessor; - private static Reflector.FieldAccessor itemsByIdAccessor; - private static Reflector.FieldAccessor eyeHeightAccessor; - private static Reflector.FieldAccessor fallFlyTicksAccessor; + private static FieldAccessor poseAccessor; + private static FieldAccessor itemsByIdAccessor; + private static FieldAccessor eyeHeightAccessor; + private static FieldAccessor fallFlyTicksAccessor; public Vivecraft_v1_20_R4() { - classEndermanFreezeWhenLookedAt = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html - classEndermanLookForPlayerGoal = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = Reflector.getField(Entity.class, EntityDataAccessor.class, 6, false); - itemsByIdAccessor = Reflector.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = Reflector.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = Reflector.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html + classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html + fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html } @Override diff --git a/Compatibility/Vivecraft_1_21_R1/build.gradle.kts b/Compatibility/Vivecraft_1_21_R1/build.gradle.kts index a3cb713..c1ebd3d 100644 --- a/Compatibility/Vivecraft_1_21_R1/build.gradle.kts +++ b/Compatibility/Vivecraft_1_21_R1/build.gradle.kts @@ -12,9 +12,10 @@ repositories { } dependencies { - paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") implementation(project(":")) - compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21.1-R0.1-SNAPSHOT") + compileOnly("com.cjcrafter:foliascheduler:0.5.0") } diff --git a/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java b/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java index 76b25d5..029463e 100644 --- a/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java +++ b/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java @@ -1,5 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; @@ -41,7 +43,6 @@ import org.bukkit.entity.Enderman; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import com.cjcrafter.vivecraft.Reflector; import com.cjcrafter.vivecraft.VSE; import com.cjcrafter.vivecraft.VivePlayer; @@ -52,19 +53,19 @@ public class Vivecraft_v1_21_R1 implements VivecraftCompatibility { private static Class classEndermanFreezeWhenLookedAt; private static Class classEndermanLookForPlayerGoal; - private static Reflector.FieldAccessor poseAccessor; - private static Reflector.FieldAccessor itemsByIdAccessor; - private static Reflector.FieldAccessor eyeHeightAccessor; - private static Reflector.FieldAccessor fallFlyTicksAccessor; + private static FieldAccessor poseAccessor; + private static FieldAccessor itemsByIdAccessor; + private static FieldAccessor eyeHeightAccessor; + private static FieldAccessor fallFlyTicksAccessor; public Vivecraft_v1_21_R1() { - classEndermanFreezeWhenLookedAt = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html - classEndermanLookForPlayerGoal = Reflector.getNMSClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = Reflector.getField(Entity.class, EntityDataAccessor.class, 6, false); - itemsByIdAccessor = Reflector.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = Reflector.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = Reflector.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html + classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html + fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html } @Override diff --git a/build.gradle.kts b/build.gradle.kts index bb7a616..c5030c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,10 +22,8 @@ dependencies { // We shade these implementation("com.github.cryptomorin:XSeries:11.1.0") - implementation("com.cjcrafter:foliascheduler:0.4.5") + implementation("com.cjcrafter:foliascheduler:0.5.0") implementation("org.bstats:bstats-bukkit:3.0.1") - implementation("xyz.jpenilla:reflection-remapper:0.1.1") // for paper auto remapping - implementation("net.fabricmc:mapping-io:0.5.0") // for paper auto remapping } java { diff --git a/src/main/java/com/cjcrafter/vivecraft/Reflector.java b/src/main/java/com/cjcrafter/vivecraft/Reflector.java deleted file mode 100644 index 3b82ef9..0000000 --- a/src/main/java/com/cjcrafter/vivecraft/Reflector.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.cjcrafter.vivecraft; - -import com.cjcrafter.foliascheduler.MinecraftVersions; -import com.cjcrafter.foliascheduler.ServerVersions; -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; -import xyz.jpenilla.reflectionremapper.ReflectionRemapper; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; - -public final class Reflector { - - private static final String nmsVersion; - - static { - String versionString = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; - nmsVersion = "net.minecraft.server." + versionString + '.'; - } - - /** - * Returns the NMS class with the given name. In mc versions 1.17 and higher, pack is - * used for the package the class is in. Previous versions ignore pack. - * - *

- * On paper servers in MC 1.20.5 and higher, packages have been remapped. We have to use the - * remapping tool to get the correct package name and class name. - * - * @param pack The non-null package name that contains the class defined by name. Make - * sure the string ends with a dot. - * @param name The non-null name of the class to find. - * @return The NMS class with that name. - */ - public static Class getNMSClass(@NotNull String pack, @NotNull String name) { - String className; - - if (MinecraftVersions.CAVES_AND_CLIFFS_1.isAtLeast()) { - className = "net.minecraft." + pack + '.' + name; - - if (ServerVersions.isPaper() && MinecraftVersions.TRAILS_AND_TAILS.get(5).isAtLeast()) { - ReflectionRemapper remapper = ReflectionRemapper.forReobfMappingsInPaperJar(); - className = remapper.remapClassOrArrayName(className); - } - } else { - className = nmsVersion + name; - } - - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - throw new InternalError("Failed to get NMS class: " + className, e); - } - } - - public static MethodAccessor getMethod(Class target, String name, Class... params) { - try { - return new MethodAccessor(target.getDeclaredMethod(name, params)); - } catch (NoSuchMethodException ex) { - throw new InternalError(ex); - } - } - - /** - * Shorthand for {@link #getMethod(Class, Class, int, Class[])}. - * - * @param target The non-null target class that declares the method. - * @param returnType The nullable returned type of the method. - * @param params The non-null parameters of the method. - * @return The non-null method that matches the given signature. - * @throws IllegalArgumentException If no such method exists. - */ - public static MethodAccessor getMethod(Class target, Class returnType, Class... params) { - return getMethod(target, returnType, 0, params); - } - - /** - * Returns a {@link Method} by its returned datatype and parameters. This - * method should be used for getting obfuscated methods, or if the name of - * the method is otherwise not guaranteed to stay the same. - *

- * If the target does not declare a matching method, this - * method will search in the parent class recursively. - * - * @param target The non-null target class that declares the method. - * @param returnType The nullable returned type of the method. - * @param index The index of the method. Sometimes this method will - * match multiple methods. For these methods, - * index is required. - * @param params The non-null parameters of the method. - * @return The non-null method that matches the given signature. - * @throws IllegalArgumentException If no such method exists. - */ - public static MethodAccessor getMethod(Class target, Class returnType, int index, Class... params) { - for (final Method method : target.getDeclaredMethods()) { - if (returnType != null && !returnType.isAssignableFrom(method.getReturnType())) - continue; - else if (!Arrays.equals(method.getParameterTypes(), params)) - continue; - else if (index-- > 0) - continue; - - //noinspection deprecation - if (!method.isAccessible()) - method.setAccessible(true); - - return new MethodAccessor(method); - } - - // Recursively check superclasses for the method - if (target.getSuperclass() != null) - return getMethod(target.getSuperclass(), returnType, index, params); - - throw new IllegalArgumentException("Cannot find field with return=" + returnType); - } - - public static FieldAccessor getField(Class target, String name) { - try { - return new FieldAccessor(target.getDeclaredField(name)); - } catch (NoSuchFieldException ex) { - throw new InternalError(ex); - } - } - - /** - * Shorthand for {@link #getField(Class, Class, int, boolean)}. - * - * @param target Which class to search in. - * @param type The type we are looking for. - * @return The non-null field. - * @throws IllegalArgumentException If no such field exists. - */ - public static FieldAccessor getField(Class target, Class type) { - return getField(target, type, 0, true); - } - - /** - * Searches for a field based on the type of the field. This has the - * advantage of being more stable across Minecraft versions (since - * obfuscated names change between versions). - * - * @param target Which class to search in. - * @param type The type we are looking for. - * @param index If there are multiple fields of the same type, which index? - * @return The non-null field. - * @throws IllegalArgumentException If no such field exists. - */ - public static FieldAccessor getField(Class target, Class type, int index, boolean skipStatic) { - for (final Field field : target.getDeclaredFields()) { - - // Type check. Make sure the field's datatype - // matches the data type we are trying to find - if (!type.isAssignableFrom(field.getType())) - continue; - if (skipStatic && Modifier.isStatic(field.getModifiers())) - continue; - if (index-- > 0) - continue; - - //noinspection deprecation - if (!field.isAccessible()) - field.setAccessible(true); - - return new FieldAccessor(field); - } - - // if the class has a superclass, then recursively check - // the super class for the field - Class superClass = target.getSuperclass(); - if (superClass != null) - return getField(superClass, type, index, skipStatic); - - throw new IllegalArgumentException("Cannot find field with type " + type); - } - - /** - * A MethodAccessor holds a reference to a declared method. The invoke - * method catches the reflection exceptions and rethrows them as an - * {@link InternalError} so you don't need a try-catch in your code. - * - * @param method The non-null method to invoke. - */ - public record MethodAccessor(Method method) { - public Object invoke(Object instance, Object... args) { - try { - return method.invoke(instance, args); - } catch (IllegalAccessException | InvocationTargetException ex) { - throw new InternalError(ex); - } - } - } - - /** - * A FieldAccessor holds a reference to a declared field. The get/set - * methods catch the reflection exceptions and rethrows them as an - * {@link InternalError} so you don't need a try-catch in your code. - * - * @param field The non-null field to access. - */ - public record FieldAccessor(Field field) { - public Object get(Object instance) { - try { - return field.get(instance); - } catch (IllegalAccessException ex) { - throw new InternalError(ex); - } - } - - public void set(Object instance, Object value) { - try { - field.set(instance, value); - } catch (IllegalAccessException ex) { - throw new InternalError(ex); - } - } - } -} \ No newline at end of file From 67c4b69501c986a03dc88860e5d197967b102e6c Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Thu, 3 Oct 2024 12:45:33 -0400 Subject: [PATCH 3/7] update to latest official shadow --- BuildVivecraftSpigotExtensions/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BuildVivecraftSpigotExtensions/build.gradle.kts b/BuildVivecraftSpigotExtensions/build.gradle.kts index 634fbb1..5bcb872 100644 --- a/BuildVivecraftSpigotExtensions/build.gradle.kts +++ b/BuildVivecraftSpigotExtensions/build.gradle.kts @@ -6,7 +6,7 @@ version = "3.1.0" plugins { `java-library` id("com.github.breadmoirai.github-release") version "2.4.1" - id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.gradleup.shadow") version "8.3.3" id("net.minecrell.plugin-yml.bukkit") version "0.6.0" } From e40200414b2b9c8ab71f7857d5651b82b9f279b4 Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Thu, 3 Oct 2024 13:00:07 -0400 Subject: [PATCH 4/7] fix reflective 1.21.1 errors --- .../vivecraft/compatibility/Vivecraft_v1_19_R3.java | 2 +- .../vivecraft/compatibility/Vivecraft_v1_20_R1.java | 2 +- .../vivecraft/compatibility/Vivecraft_v1_20_R2.java | 2 +- .../vivecraft/compatibility/Vivecraft_v1_20_R3.java | 2 +- .../vivecraft/compatibility/Vivecraft_v1_20_R4.java | 2 +- .../vivecraft/compatibility/Vivecraft_v1_21_R1.java | 12 ++++++------ .../vivecraft/compatibility/CompatibilityAPI.java | 10 +++++----- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java b/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java index f713e8e..2e51a1a 100644 --- a/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java +++ b/Compatibility/Vivecraft_1_19_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_19_R3.java @@ -64,7 +64,7 @@ public class Vivecraft_v1_19_R3 implements VivecraftCompatibility { public Vivecraft_v1_19_R3() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bf"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/Entity.html fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bw"); // https://nms.screamingsandals.org/1.19.4/net/minecraft/world/entity/LivingEntity.html diff --git a/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java b/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java index d630348..6d11b69 100644 --- a/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java +++ b/Compatibility/Vivecraft_1_20_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R1.java @@ -61,7 +61,7 @@ public class Vivecraft_v1_20_R1 implements VivecraftCompatibility { public Vivecraft_v1_20_R1() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/Entity.html fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "by"); // https://nms.screamingsandals.org/1.20.1/net/minecraft/world/entity/LivingEntity.html diff --git a/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java b/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java index 3705bae..27c0382 100644 --- a/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java +++ b/Compatibility/Vivecraft_1_20_R2/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R2.java @@ -61,7 +61,7 @@ public class Vivecraft_v1_20_R2 implements VivecraftCompatibility { public Vivecraft_v1_20_R2() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html diff --git a/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java b/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java index 722110f..bfab536 100644 --- a/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java +++ b/Compatibility/Vivecraft_1_20_R3/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R3.java @@ -61,7 +61,7 @@ public class Vivecraft_v1_20_R3 implements VivecraftCompatibility { public Vivecraft_v1_20_R3() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html diff --git a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java index e4cebd4..bb737d9 100644 --- a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java +++ b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java @@ -62,7 +62,7 @@ public class Vivecraft_v1_20_R4 implements VivecraftCompatibility { public Vivecraft_v1_20_R4() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html diff --git a/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java b/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java index 029463e..0c7409b 100644 --- a/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java +++ b/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java @@ -1,6 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.MethodInvoker; import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -56,16 +57,16 @@ public class Vivecraft_v1_21_R1 implements VivecraftCompatibility { private static FieldAccessor poseAccessor; private static FieldAccessor itemsByIdAccessor; private static FieldAccessor eyeHeightAccessor; - private static FieldAccessor fallFlyTicksAccessor; + private static MethodInvoker resetFallDistanceMethod; public Vivecraft_v1_21_R1() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); - poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_NOT_STATIC); + poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "be"); // https://nms.screamingsandals.org/1.21.1/net/minecraft/world/entity/Entity.html + resetFallDistanceMethod = ReflectionUtil.getMethod(Entity.class, "n"); // https://nms.screamingsandals.org/1.21.1/net/minecraft/world/entity/Entity.html } @Override @@ -106,8 +107,7 @@ public void injectPoseOverrider(Player bukkit) { @Override public void resetFall(Player bukkit) { net.minecraft.world.entity.player.Player player = ((CraftPlayer) bukkit).getHandle(); - player.fallDistance = 0f; - fallFlyTicksAccessor.set(player, 0); + resetFallDistanceMethod.invoke(player); } @Override diff --git a/src/main/java/com/cjcrafter/vivecraft/compatibility/CompatibilityAPI.java b/src/main/java/com/cjcrafter/vivecraft/compatibility/CompatibilityAPI.java index b41f976..e4fae7b 100644 --- a/src/main/java/com/cjcrafter/vivecraft/compatibility/CompatibilityAPI.java +++ b/src/main/java/com/cjcrafter/vivecraft/compatibility/CompatibilityAPI.java @@ -1,5 +1,6 @@ package com.cjcrafter.vivecraft.compatibility; +import com.cjcrafter.foliascheduler.util.MinecraftVersions; import org.bukkit.Bukkit; import com.cjcrafter.vivecraft.VSE; @@ -16,9 +17,8 @@ public static VivecraftCompatibility getCompatibility() { // When compatibility has not yet been setup if (compatibility == null) { - // Get the version string like '1_19_R2' for 1.19.3 - String version = Bukkit.getServer().getClass().getPackageName().replace(".", ",").split(",")[3]; - + // Get the version string like 'v1_19_R2' for 1.19.3 + String version = MinecraftVersions.getCurrent().toProtocolString(); try { // If a class exists for this minecraft protocol version, then @@ -27,11 +27,11 @@ public static VivecraftCompatibility getCompatibility() { Object instance = clazz.getDeclaredConstructor().newInstance(); compatibility = (VivecraftCompatibility) instance; - } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { + } catch (ReflectiveOperationException ex) { Logger log = VSE.me.getLogger(); log.log(Level.WARNING, "Your version '" + version + "' is not fully supported"); log.log(Level.WARNING, "Check Spigot for a list of supported Minecraft versions"); - log.log(Level.WARNING, "If you just updated your server to the newest version of Minecraft, make sure you update Vivecraft_Spigot_Extensions as well!"); + log.log(Level.WARNING, "If you just updated your server to the newest version of Minecraft, make sure you update VivecraftSpigot as well!"); log.log(Level.WARNING, "https://www.spigotmc.org/resources/111303/"); log.log(Level.WARNING, "The following features will now be disabled: "); log.log(Level.WARNING, " - CreeperRadius"); From 151504485e2fa0f6dfc9110eacbb8c910aedd0c4 Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Thu, 3 Oct 2024 13:02:05 -0400 Subject: [PATCH 5/7] fix reflective 1.20.6 errors --- .../vivecraft/compatibility/Vivecraft_v1_20_R4.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java index bb737d9..05c761c 100644 --- a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java +++ b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java @@ -1,6 +1,7 @@ package com.cjcrafter.vivecraft.compatibility; import com.cjcrafter.foliascheduler.util.FieldAccessor; +import com.cjcrafter.foliascheduler.util.MethodInvoker; import com.cjcrafter.foliascheduler.util.ReflectionUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -56,16 +57,16 @@ public class Vivecraft_v1_20_R4 implements VivecraftCompatibility { private static FieldAccessor poseAccessor; private static FieldAccessor itemsByIdAccessor; private static FieldAccessor eyeHeightAccessor; - private static FieldAccessor fallFlyTicksAccessor; + private static MethodInvoker resetFallDistanceMethod; public Vivecraft_v1_20_R4() { - classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html + classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.6/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); - eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bi"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/Entity.html - fallFlyTicksAccessor = ReflectionUtil.getField(LivingEntity.class, "bx"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/LivingEntity.html + eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bg"); // https://nms.screamingsandals.org/1.20.6/net/minecraft/world/entity/Entity.html + resetFallDistanceMethod = ReflectionUtil.getMethod(LivingEntity.class, "n"); // https://nms.screamingsandals.org/1.20.6/net/minecraft/world/entity/Entity.html } @Override @@ -106,8 +107,7 @@ public void injectPoseOverrider(Player bukkit) { @Override public void resetFall(Player bukkit) { net.minecraft.world.entity.player.Player player = ((CraftPlayer) bukkit).getHandle(); - player.fallDistance = 0f; - fallFlyTicksAccessor.set(player, 0); + resetFallDistanceMethod.invoke(player); } @Override From e20037fb96f388619961071294717e235edb622a Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Thu, 3 Oct 2024 13:25:51 -0400 Subject: [PATCH 6/7] Fix pose injection --- .../vivecraft/compatibility/Vivecraft_v1_20_R4.java | 7 +++---- .../vivecraft/compatibility/Vivecraft_v1_21_R1.java | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java index 05c761c..7e73587 100644 --- a/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java +++ b/Compatibility/Vivecraft_1_20_R4/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_20_R4.java @@ -64,7 +64,7 @@ public Vivecraft_v1_20_R4() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.6/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); - itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, SynchedEntityData.DataItem[].class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "bg"); // https://nms.screamingsandals.org/1.20.6/net/minecraft/world/entity/Entity.html resetFallDistanceMethod = ReflectionUtil.getMethod(LivingEntity.class, "n"); // https://nms.screamingsandals.org/1.20.6/net/minecraft/world/entity/Entity.html } @@ -99,9 +99,8 @@ public void injectPlayer(Player bukkit) { public void injectPoseOverrider(Player bukkit) { ServerPlayer player = ((CraftPlayer) bukkit).getHandle(); EntityDataAccessor poseObj = (EntityDataAccessor) poseAccessor.get(player); - Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) itemsByIdAccessor.get(player.getEntityData()); - InjectedDataWatcherItem item = new InjectedDataWatcherItem(poseObj, Pose.STANDING, bukkit); - entries.put(poseObj.id(), item); + SynchedEntityData.DataItem[] items = (SynchedEntityData.DataItem[]) itemsByIdAccessor.get(player.getEntityData()); + items[poseObj.id()] = new InjectedDataWatcherItem(poseObj, Pose.STANDING, bukkit); } @Override diff --git a/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java b/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java index 0c7409b..70f55ce 100644 --- a/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java +++ b/Compatibility/Vivecraft_1_21_R1/src/main/java/com/cjcrafter/vivecraft/compatibility/Vivecraft_v1_21_R1.java @@ -64,7 +64,7 @@ public Vivecraft_v1_21_R1() { classEndermanFreezeWhenLookedAt = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$a"); // https://nms.screamingsandals.org/1.20.2/net/minecraft/world/entity/monster/EnderMan.html classEndermanLookForPlayerGoal = ReflectionUtil.getMinecraftClass("world.entity.monster", "EntityEnderman$PathfinderGoalPlayerWhoLookedAtTarget"); poseAccessor = ReflectionUtil.getField(Entity.class, EntityDataAccessor.class, 6, ReflectionUtil.IS_STATIC); - itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); + itemsByIdAccessor = ReflectionUtil.getField(SynchedEntityData.class, SynchedEntityData.DataItem[].class); eyeHeightAccessor = ReflectionUtil.getField(Entity.class, "be"); // https://nms.screamingsandals.org/1.21.1/net/minecraft/world/entity/Entity.html resetFallDistanceMethod = ReflectionUtil.getMethod(Entity.class, "n"); // https://nms.screamingsandals.org/1.21.1/net/minecraft/world/entity/Entity.html } @@ -99,9 +99,8 @@ public void injectPlayer(Player bukkit) { public void injectPoseOverrider(Player bukkit) { ServerPlayer player = ((CraftPlayer) bukkit).getHandle(); EntityDataAccessor poseObj = (EntityDataAccessor) poseAccessor.get(player); - Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) itemsByIdAccessor.get(player.getEntityData()); - InjectedDataWatcherItem item = new InjectedDataWatcherItem(poseObj, Pose.STANDING, bukkit); - entries.put(poseObj.id(), item); + SynchedEntityData.DataItem[] items = (SynchedEntityData.DataItem[]) itemsByIdAccessor.get(player.getEntityData()); + items[poseObj.id()] = new InjectedDataWatcherItem(poseObj, Pose.STANDING, bukkit); } @Override From 697461f7c1fc43d73dc0f567d82233d0e9a9ecdc Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Thu, 3 Oct 2024 17:57:23 -0400 Subject: [PATCH 7/7] fix maven publishing --- .gitignore | 1 - .../build.gradle.kts | 2 +- build.gradle.kts | 46 ++++++------------- gradle.properties | 1 + 4 files changed, 17 insertions(+), 33 deletions(-) create mode 100644 gradle.properties diff --git a/.gitignore b/.gitignore index 6ae227d..11c60b3 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,6 @@ lib/ # Ignore Gradle project-specific cache directory .gradle -gradle.properties # Ignore Gradle build output directory build diff --git a/BuildVivecraftSpigotExtensions/build.gradle.kts b/BuildVivecraftSpigotExtensions/build.gradle.kts index 5bcb872..ff55e60 100644 --- a/BuildVivecraftSpigotExtensions/build.gradle.kts +++ b/BuildVivecraftSpigotExtensions/build.gradle.kts @@ -1,7 +1,7 @@ import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask group = "com.cjcrafter" -version = "3.1.0" +version = findProperty("version").toString() plugins { `java-library` diff --git a/build.gradle.kts b/build.gradle.kts index c5030c7..79730e7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { `java-library` `maven-publish` signing - id("io.codearte.nexus-staging") version "0.30.0" + id("io.github.gradle-nexus.publish-plugin") version "2.0.0" id("io.papermc.paperweight.userdev") version "1.7.1" apply false } @@ -57,24 +57,24 @@ val sourcesJar by tasks.registering(Jar::class) { from(sourceSets.main.get().allSource) } -nexusStaging { - serverUrl = "https://s01.oss.sonatype.org/service/local/" - packageGroup = "com.cjcrafter" - stagingProfileId = findProperty("OSSRH_ID").toString() - username = findProperty("OSSRH_USERNAME").toString() - password = findProperty("OSSRH_PASSWORD").toString() - numberOfRetries = 30 - delayBetweenRetriesInMillis = 3000 +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username.set(System.getenv("OSSRH_USERNAME") ?: findProperty("OSSRH_USERNAME").toString()) + password.set(System.getenv("OSSRH_PASSWORD") ?: findProperty("OSSRH_PASSWORD").toString()) + packageGroup.set("com.cjcrafter") + } + } } -// Signing artifacts signing { isRequired = true - useInMemoryPgpKeys( - findProperty("SIGNING_KEY_ID").toString(), - findProperty("SIGNING_PRIVATE_KEY").toString(), - findProperty("SIGNING_PASSWORD").toString() + System.getenv("SIGNING_KEY_ID") ?: findProperty("SIGNING_KEY_ID").toString(), + System.getenv("SIGNING_PRIVATE_KEY") ?: findProperty("SIGNING_PRIVATE_KEY").toString(), + System.getenv("SIGNING_PASSWORD") ?: findProperty("SIGNING_PASSWORD").toString(), ) sign(publishing.publications) } @@ -94,8 +94,7 @@ publishing { groupId = "com.cjcrafter" artifactId = "vivecraft" - // version is set in the BuildVivecraftSpigotExtensions' build.gradle.kts file - version = "3.0.0" + version = findProperty("version").toString() licenses { license { @@ -118,19 +117,4 @@ publishing { } } } - - repositories { - maven { - url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2") - credentials { - username = findProperty("OSSRH_USERNAME").toString() - password = findProperty("OSSRH_PASSWORD").toString() - } - } - } -} - -// After publishing, the nexus plugin will automatically close and release -tasks.named("publish") { - finalizedBy("closeAndReleaseRepository") } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..fe5fb99 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +version=3.1.0 \ No newline at end of file