diff --git a/api/build.gradle.kts b/api/build.gradle.kts index e97c6db0..be5ab228 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -32,17 +32,17 @@ dependencies { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 toolchain { - languageVersion = JavaLanguageVersion.of(17) + languageVersion = JavaLanguageVersion.of(21) } withSourcesJar() } tasks.withType { options.encoding = "UTF-8" - options.release.set(17) + options.release.set(21) dependsOn(tasks.clean) } diff --git a/compatibility/build.gradle.kts b/compatibility/build.gradle.kts index 2614f732..869c3747 100644 --- a/compatibility/build.gradle.kts +++ b/compatibility/build.gradle.kts @@ -43,7 +43,7 @@ dependencies { compileOnly(files("libs/mcMMO-api.jar")) compileOnly("net.Indyuce:MMOCore-API:1.12.1-SNAPSHOT") // compileOnly("dev.aurelium:auraskills-api-bukkit:2.2.7") - compileOnly(files("libs/AuraSkills-2.2.7.jar")) + compileOnly(files("libs/AuraSkills-2.3.4.jar")) compileOnly("com.github.Archy-X:AureliumSkills:Beta1.3.21") compileOnly("com.github.Zrips:Jobs:v5.2.2.3") // quest @@ -83,15 +83,15 @@ dependencies { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 toolchain { - languageVersion = JavaLanguageVersion.of(17) + languageVersion = JavaLanguageVersion.of(21) } } tasks.withType { options.encoding = "UTF-8" - options.release.set(17) + options.release.set(21) dependsOn(tasks.clean) } \ No newline at end of file diff --git a/compatibility/j21/build.gradle.kts b/compatibility/j21/build.gradle.kts index 5c84544d..a4be882c 100644 --- a/compatibility/j21/build.gradle.kts +++ b/compatibility/j21/build.gradle.kts @@ -12,6 +12,8 @@ dependencies { compileOnly("com.nexomc:nexo:1.7.3") compileOnly("net.momirealms:craft-engine-core:0.0.57") compileOnly("net.momirealms:craft-engine-bukkit:0.0.57") + compileOnly("net.momirealms:sparrow-heart:${rootProject.properties["sparrow_heart_version"]}") + compileOnly(files("libs/AuraSkills-2.3.4.jar")) } tasks.withType { diff --git a/compatibility/libs/AuraSkills-2.2.7.jar b/compatibility/libs/AuraSkills-2.3.4.jar similarity index 57% rename from compatibility/libs/AuraSkills-2.2.7.jar rename to compatibility/libs/AuraSkills-2.3.4.jar index c4aceca8..92be04f4 100644 Binary files a/compatibility/libs/AuraSkills-2.2.7.jar and b/compatibility/libs/AuraSkills-2.3.4.jar differ diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/item/AuraSkillItemProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/item/AuraSkillItemProvider.java index 028908f0..9b615efd 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/item/AuraSkillItemProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/item/AuraSkillItemProvider.java @@ -17,13 +17,13 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.hooks.WorldGuardFlags.FlagKey; import dev.aurelium.auraskills.bukkit.hooks.WorldGuardHook; import dev.aurelium.auraskills.bukkit.loot.context.MobContext; -import dev.aurelium.auraskills.bukkit.loot.context.SourceContext; -import dev.aurelium.auraskills.bukkit.loot.type.CommandLoot; import dev.aurelium.auraskills.bukkit.loot.type.EntityLoot; import dev.aurelium.auraskills.bukkit.loot.type.ItemLoot; import dev.aurelium.auraskills.bukkit.source.FishingLeveler; import dev.aurelium.auraskills.common.commands.CommandExecutor; import dev.aurelium.auraskills.common.hooks.PlaceholderHook; +import dev.aurelium.auraskills.common.loot.CommandLoot; +import dev.aurelium.auraskills.common.loot.SourceContext; import dev.aurelium.auraskills.common.message.MessageKey; import dev.aurelium.auraskills.common.user.User; import dev.aurelium.auraskills.common.util.text.TextUtil; @@ -41,6 +41,8 @@ import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,6 +51,9 @@ import java.util.HashSet; import java.util.Locale; import java.util.Random; import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +import static dev.aurelium.auraskills.bukkit.ref.BukkitItemRef.unwrap; /* * @@ -88,7 +93,7 @@ public class AuraSkillItemProvider implements ItemProvider { User user = plugin.getUser(context.holder()); Skill skill = originalSource != null ? originalSource.skill() : Skills.FISHING; - LootTable table = plugin.getLootTableManager().getLootTable(skill); + LootTable table = plugin.getLootManager().getLootTable(skill); if (table == null) return originalItem; for (LootPool pool : table.getPools()) { // Calculate chance for pool @@ -115,7 +120,7 @@ public class AuraSkillItemProvider implements ItemProvider { if (random.nextDouble() < chance) { // Pool is selected XpSource contextSource = originalSource != null ? originalSource.source() : null; - Loot selectedLoot = selectLoot(pool, new SourceContext(contextSource)); + Loot selectedLoot = selectLoot(pool, new dev.aurelium.auraskills.common.loot.SourceContext(contextSource)); // Give loot if (selectedLoot == null) { // Continue iterating pools continue; @@ -220,7 +225,7 @@ public class AuraSkillItemProvider implements ItemProvider { int amount = generateAmount(loot.getMinAmount(), loot.getMaxAmount()); if (amount == 0) return new ItemStack(Material.AIR); - ItemStack drop = loot.getItem().supplyItem(plugin, table); + ItemStack drop = generateDamaged(unwrap(loot.getItem().supplyItem(plugin, table)), loot.getMinDamage(), loot.getMaxDamage()); drop.setAmount(amount); attemptSendMessage(player, loot); @@ -229,6 +234,37 @@ public class AuraSkillItemProvider implements ItemProvider { return drop; } + private ItemStack generateDamaged(ItemStack drop, double minDamage, double maxDamage) { + if (minDamage >= 0.0 && minDamage <= 1.0 && + maxDamage >= 0.0 && maxDamage <= 1.0 && + minDamage <= maxDamage) { + + // Check if the item is damageable. + if (drop == null) { + return drop; + } + + ItemMeta meta = drop.getItemMeta(); + if (meta instanceof Damageable damageable) { + int damage = 0; // Default to 0 damage + short durability = drop.getType().getMaxDurability(); + int minDamageValue = (int) (durability * minDamage); // E.g. 1561 * 0.0 = 0 -> resulting in an undamaged item. + int maxDamageValue = (int) (durability * maxDamage); // E.g. 1561 * 0.5 = 780 -> resulting in a max 50% damaged item. + + if (minDamage == maxDamage) { + damage = maxDamageValue; + } else { + damage = ThreadLocalRandom.current().nextInt(minDamageValue, maxDamageValue); + } + + damageable.setDamage(damage); + drop.setItemMeta(meta); + } + } + + return drop; + } + private void giveXp(Player player, Loot loot, @Nullable XpSource source, Skill skill) { if (plugin.getHookManager().isRegistered(WorldGuardHook.class)) { // Check generic xp-gain and skill-specific flags @@ -312,13 +348,14 @@ public class AuraSkillItemProvider implements ItemProvider { protected Loot selectLoot(LootPool pool, @NotNull LootContext providedContext) { return pool.rollLoot(loot -> { if (providedContext instanceof SourceContext sourceContext) { + XpSource providedSource = sourceContext.source(); Set lootContexts = loot.getValues().getContexts().get("sources"); // Make sure the loot defines a sources context and the provided context exists if (lootContexts != null && sourceContext.source() != null) { boolean matched = false; for (LootContext context : lootContexts) { // Go through LootContext and cast to Source - if (context instanceof SourceContext sourceLootContext) { - if (sourceLootContext.source().equals(sourceContext.source())) { // Check if source matches one of the contexts + if (context instanceof SourceContext sourceContext1) { + if (sourceContext1.source().equals(providedSource)) { // Check if source matches one of the contexts matched = true; break; } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 8dfa4d32..80b2f747 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -84,15 +84,15 @@ artifacts { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 toolchain { - languageVersion = JavaLanguageVersion.of(17) + languageVersion = JavaLanguageVersion.of(21) } } tasks.withType { options.encoding = "UTF-8" - options.release.set(17) + options.release.set(21) dependsOn(tasks.clean) } \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java index af852575..dfdb54d4 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java @@ -68,7 +68,7 @@ public class BukkitIntegrationManager implements IntegrationManager { this.plugin = plugin; try { this.load(); - } catch (Exception e) { + } catch (Throwable e) { plugin.getPluginLogger().warn("Failed to load integrations", e); } finally { instance = this; diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemFactory.java b/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemFactory.java index 0a787ac8..dacb0d9e 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemFactory.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemFactory.java @@ -48,7 +48,7 @@ public abstract class BukkitItemFactory extends ItemFactory { return new ComponentItemFactory(plugin); } - case "1.21.5", "1.21.6" -> { + case "1.21.5", "1.21.6", "1.21.7" -> { return new ComponentItemFactory1_21_5(plugin); } default -> throw new IllegalStateException("Unsupported server version: " + plugin.getServerVersion()); diff --git a/gradle.properties b/gradle.properties index ab76f497..53dfe120 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=2.3.12 +project_version=2.3.13 config_version=38 project_group=net.momirealms @@ -20,7 +20,7 @@ h2_driver_version=2.3.232 sqlite_driver_version=3.49.1.0 adventure_bundle_version=4.23.0 adventure_platform_version=4.4.0 -sparrow_heart_version=0.57 +sparrow_heart_version=0.58 cloud_core_version=2.0.0 cloud_services_version=2.0.0 cloud_brigadier_version=2.0.0-beta.10