From a33e3c1d5303c804d9adbebe7623e01cb4340788 Mon Sep 17 00:00:00 2001 From: NotAlexNoyle Date: Fri, 15 Aug 2025 17:25:06 -0400 Subject: [PATCH] Update gradle to 8.14.3, add formatting --- build.gradle.kts | 95 +++-- config/checkstyle/checkstyle.xml | 34 ++ config/formatter/eclipse-java-formatter.xml | 404 ++++++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/plugin/BetterPickupOG.java | 10 + src/main/java/plugin/DropListener.java | 29 +- src/main/java/plugin/ReloadCommand.java | 13 +- src/main/java/plugin/Utils.java | 16 +- 8 files changed, 554 insertions(+), 49 deletions(-) create mode 100644 config/checkstyle/checkstyle.xml create mode 100644 config/formatter/eclipse-java-formatter.xml diff --git a/build.gradle.kts b/build.gradle.kts index 67f7081..5b5d830 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,83 +1,102 @@ +/* ------------------------------ Plugins ------------------------------ */ plugins { - id("java") // Tell gradle this is a java project. - id("java-library") // Import helper for source-based libraries. - id("com.diffplug.spotless") version "7.0.4" // Import auto-formatter. - id("com.gradleup.shadow") version "8.3.6" // Import shadow API. - eclipse // Import eclipse plugin for IDE integration. + id("java") // Import Java plugin. + id("java-library") // Import Java Library plugin. + id("com.diffplug.spotless") version "7.0.4" // Import Spotless plugin. + id("com.gradleup.shadow") version "8.3.6" // Import Shadow plugin. + id("checkstyle") // Import Checkstyle plugin. + eclipse // Import Eclipse plugin. + kotlin("jvm") version "2.1.21" // Import Kotlin JVM plugin. } +/* --------------------------- JDK / Kotlin ---------------------------- */ java { - // Declare java version. - sourceCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_17 // Compile with JDK 17 compatibility. + toolchain { // Select Java toolchain. + languageVersion.set(JavaLanguageVersion.of(17)) // Use JDK 17. + vendor.set(JvmVendorSpec.GRAAL_VM) // Use GraalVM CE. + } } -group = "net.trueog.betterpickupog" // Declare bundle identifier. +kotlin { jvmToolchain(17) } + +/* ----------------------------- Metadata ------------------------------ */ +group = "net.trueog.betterpickup-og" // Declare bundle identifier. version = "1.0" // Declare plugin version (will be in .jar). val apiVersion = "1.19" // Declare minecraft server target version. +/* ----------------------------- Resources ----------------------------- */ tasks.named("processResources") { val props = mapOf("version" to version, "apiVersion" to apiVersion) - inputs.properties(props) // Indicates to rerun if version changes. - filesMatching("plugin.yml") { expand(props) } - from("LICENSE") { // Bundle license into .jars. - into("/") - } + from("LICENSE") { into("/") } // Bundle licenses into jarfiles. } +/* ---------------------------- Repos ---------------------------------- */ repositories { - mavenCentral() - gradlePluginPortal() - maven { url = uri("https://repo.purpurmc.org/snapshots") } + mavenCentral() // Import the Maven Central Maven Repository. + gradlePluginPortal() // Import the Gradle Plugin Portal Maven Repository. + maven { url = uri("https://repo.purpurmc.org/snapshots") } // Import the PurpurMC Maven Repository. } +/* ---------------------- Java project deps ---------------------------- */ dependencies { - compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare purpur API version to be packaged. + compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare Purpur API version to be packaged. compileOnly("io.github.miniplaceholders:miniplaceholders-api:2.2.3") // Import MiniPlaceholders API. } -tasks.withType().configureEach { // Ensure reproducible builds. +/* ---------------------- Reproducible jars ---------------------------- */ +tasks.withType().configureEach { // Ensure reproducible .jars isPreserveFileTimestamps = false isReproducibleFileOrder = true } +/* ----------------------------- Shadow -------------------------------- */ tasks.shadowJar { exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed. archiveClassifier.set("") // Use empty string instead of null. minimize() } -tasks.build { - dependsOn(tasks.spotlessApply) - dependsOn(tasks.shadowJar) -} +tasks.jar { archiveClassifier.set("part") } // Applies to root jarfile only. -tasks.jar { archiveClassifier.set("part") } +tasks.build { dependsOn(tasks.spotlessApply, tasks.shadowJar) } // Build depends on spotless and shadow. +/* --------------------------- Javac opts ------------------------------- */ tasks.withType().configureEach { - options.compilerArgs.add("-parameters") - options.compilerArgs.add("-Xlint:deprecation") // Triggers deprecation warning messages. - options.encoding = "UTF-8" - options.isFork = true -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - vendor = JvmVendorSpec.GRAAL_VM - } + options.compilerArgs.add("-parameters") // Enable reflection for java code. + options.isFork = true // Run javac in its own process. + options.compilerArgs.add("-Xlint:deprecation") // Trigger deprecation warning messages. + options.encoding = "UTF-8" // Use UTF-8 file encoding. } +/* ----------------------------- Auto Formatting ------------------------ */ spotless { java { - removeUnusedImports() - palantirJavaFormat() + eclipse().configFile("config/formatter/eclipse-java-formatter.xml") // Eclipse java formatting. + leadingTabsToSpaces() // Convert leftover leading tabs to spaces. + removeUnusedImports() // Remove imports that aren't being called. } kotlinGradle { - ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) } - target("build.gradle.kts", "settings.gradle.kts") + ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) } // JetBrains Kotlin formatting. + target("build.gradle.kts", "settings.gradle.kts") // Gradle files to format. } } + +checkstyle { + toolVersion = "10.18.1" // Declare checkstyle version to use. + configFile = file("config/checkstyle/checkstyle.xml") // Point checkstyle to config file. + isIgnoreFailures = true // Don't fail the build if checkstyle does not pass. + isShowViolations = true // Show the violations in any IDE with the checkstyle plugin. +} + +tasks.named("compileJava") { + dependsOn("spotlessApply") // Run spotless before compiling with the JDK. +} + +tasks.named("spotlessCheck") { + dependsOn("spotlessApply") // Run spotless before checking if spotless ran. +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..4c3ab95 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/formatter/eclipse-java-formatter.xml b/config/formatter/eclipse-java-formatter.xml new file mode 100644 index 0000000..a3e01a0 --- /dev/null +++ b/config/formatter/eclipse-java-formatter.xml @@ -0,0 +1,404 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ff23a68..d4081da 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/plugin/BetterPickupOG.java b/src/main/java/plugin/BetterPickupOG.java index 76bb549..e85c8d5 100644 --- a/src/main/java/plugin/BetterPickupOG.java +++ b/src/main/java/plugin/BetterPickupOG.java @@ -29,12 +29,14 @@ public class BetterPickupOG extends JavaPlugin { // Listeners. getServer().getPluginManager().registerEvents(new DropListener(), this); + } @Override public void onDisable() { this.getLogger().info("BetterPickup-OG shut down successfully."); + } public void reload() { @@ -46,6 +48,7 @@ public class BetterPickupOG extends JavaPlugin { invulnerable = getConfig().getBoolean("invulnerable"); playerDropDelay = getConfig().getInt("playerDropDelay"); stealDelay = getConfig().getInt("stealDelay"); + } // Class constructor. @@ -53,30 +56,37 @@ public class BetterPickupOG extends JavaPlugin { // Pass instance of main to other classes. return plugin; + } public boolean autoPickup() { return autoPickup; + } public int blockDropDelay() { return blockDropDelay; + } public boolean invulnerable() { return invulnerable; + } public int playerDropDelay() { return playerDropDelay; + } public int stealDelay() { return stealDelay; + } + } diff --git a/src/main/java/plugin/DropListener.java b/src/main/java/plugin/DropListener.java index 6212006..88e89a8 100644 --- a/src/main/java/plugin/DropListener.java +++ b/src/main/java/plugin/DropListener.java @@ -47,9 +47,13 @@ public class DropListener implements Listener { item.teleport(entry.getValue()); i.remove(); + } + } + } + }.runTaskTimer(plugin, 0L, 1L); new BukkitRunnable() { @@ -58,18 +62,22 @@ public class DropListener implements Listener { public void run() { // Iterate through player dropped items. - Iterator>> i = - playerDrops.entrySet().iterator(); + Iterator>> i = playerDrops.entrySet().iterator(); while (i.hasNext()) { // Clean up. if (!i.next().getKey().isValid()) { i.remove(); + } + } + } + }.runTaskTimer(plugin, 0L, 6000L); // Every 5 minutes when items despawn. + } @EventHandler @@ -82,15 +90,19 @@ public class DropListener implements Listener { if (plugin.autoPickup()) { blockDrops.put(i, event.getPlayer()); - playerDrops.put( - i, + playerDrops.put(i, new AbstractMap.SimpleEntry(event.getPlayer(), plugin.blockDropDelay() + 1)); + } + if (plugin.invulnerable()) { i.setInvulnerable(true); + } + } + } @EventHandler @@ -99,10 +111,11 @@ public class DropListener implements Listener { event.getItemDrop().setPickupDelay(plugin.playerDropDelay()); if (plugin.stealDelay() > 0) { - playerDrops.put( - event.getItemDrop(), + playerDrops.put(event.getItemDrop(), new AbstractMap.SimpleEntry(event.getPlayer(), plugin.stealDelay())); + } + } @EventHandler @@ -123,7 +136,11 @@ public class DropListener implements Listener { // Remove from the map. playerDrops.remove(item); + } + } + } + } diff --git a/src/main/java/plugin/ReloadCommand.java b/src/main/java/plugin/ReloadCommand.java index 374a33d..91a9e58 100644 --- a/src/main/java/plugin/ReloadCommand.java +++ b/src/main/java/plugin/ReloadCommand.java @@ -27,6 +27,7 @@ public class ReloadCommand implements CommandExecutor { Logger logger = Bukkit.getServer().getLogger(); // Log the output to the console. logger.info(Utils.legacySerializerAnyCase(info).content()); + } return true; @@ -35,13 +36,15 @@ public class ReloadCommand implements CommandExecutor { if (!sender.hasPermission("betterpickup.reload")) { - // Since the sender doesn't have permission, it can't be the console, so sender can be casted directly + // Since the sender doesn't have permission, it can't be the console, so sender + // can be casted directly // to Player. // Send formatted message. - Utils.betterPickupOGMessage( - (Player) sender, "&cERROR: You do not have permission to run this command."); + Utils.betterPickupOGMessage((Player) sender, + "&cERROR: You do not have permission to run this command."); return true; + } // Reload config. @@ -63,6 +66,7 @@ public class ReloadCommand implements CommandExecutor { Logger logger = Bukkit.getServer().getLogger(); // Log the output to the console. logger.info(Utils.legacySerializerAnyCase(reload).content()); + } return true; @@ -70,6 +74,9 @@ public class ReloadCommand implements CommandExecutor { } else { return false; + } + } + } diff --git a/src/main/java/plugin/Utils.java b/src/main/java/plugin/Utils.java index 3197666..36bb56f 100644 --- a/src/main/java/plugin/Utils.java +++ b/src/main/java/plugin/Utils.java @@ -10,6 +10,7 @@ public class Utils { public static void betterPickupOGMessage(Player p, String message) { p.sendMessage(legacySerializerAnyCase((message))); + } public static TextComponent legacySerializerAnyCase(String subject) { @@ -21,7 +22,9 @@ public class Utils { if (c == '&') { count++; + } + } // Create an array to store the positions of '&' characters @@ -35,30 +38,38 @@ public class Utils { if (isUpperBukkitCode(subject.charAt(i + 1))) { subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1))); + } positions[index++] = i; + } + } return LegacyComponentSerializer.legacyAmpersand().deserialize(subject); + } private static boolean isUpperBukkitCode(char input) { - char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'}; + char[] bukkitColorCodes = { 'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R' }; boolean match = false; // Loop through each character in the array. for (char c : bukkitColorCodes) { + // Check if the current character in the array is equal to the input character. if (c == input) { match = true; + } + } return match; + } private static String replaceCharAtIndex(String original, int index, char newChar) { @@ -68,9 +79,12 @@ public class Utils { // Create a new string with the replaced character return original.substring(0, index) + newChar + original.substring(index + 1); + } // If the index is invalid, return the original string return original; + } + }