From 5041662a604a5dd3d88f2513ff636f9648b10956 Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Wed, 17 May 2023 01:06:33 +0800 Subject: [PATCH] 3.2.1 --- build.gradle | 2 +- libs/ProtectionLib.jar | Bin 16317 -> 16319 bytes .../customplugin/oraxen/OraxenPluginImpl.java | 4 +- .../customcrops/api/object/action/Action.java | 2 +- .../api/object/action/BreakImpl.java | 61 ++++++++++++---- .../api/object/action/ChainImpl.java | 4 +- .../api/object/action/CommandActionImpl.java | 8 +- .../api/object/action/DropItemImpl.java | 17 ++++- .../api/object/action/GiveMoneyImpl.java | 2 +- .../api/object/action/JobXPImpl.java | 2 +- .../api/object/action/MessageActionImpl.java | 8 +- .../api/object/action/ParticleImpl.java | 6 +- .../api/object/action/PotionEffectImpl.java | 2 +- .../api/object/action/ReplantImpl.java | 69 +++++++++++++----- .../api/object/action/SkillXPImpl.java | 2 +- .../api/object/action/SoundActionImpl.java | 2 +- .../api/object/action/SwingHandImpl.java | 2 +- .../api/object/action/VanillaXPImpl.java | 2 +- .../api/object/action/VariationImpl.java | 11 ++- .../customcrops/api/object/loot/Loot.java | 5 +- src/main/resources/config.yml | 10 +-- 21 files changed, 145 insertions(+), 76 deletions(-) diff --git a/build.gradle b/build.gradle index a7825d3..ddd44cc 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '3.2.0' +version = '3.2.1' repositories { mavenCentral() diff --git a/libs/ProtectionLib.jar b/libs/ProtectionLib.jar index 10737ff72a4c74aac7c38789af498085b349fec8..366a676aa670a2da4e4a35d8ad3e266f6a45881b 100644 GIT binary patch delta 1424 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[CustomCrops] ItemFrame not exists: " + id); - entity.remove(); + OraxenFurniture.remove(entity, null); return null; } } @@ -97,7 +97,7 @@ public class OraxenPluginImpl implements PlatformInterface { return itemDisplay; else { AdventureUtils.consoleMessage("[CustomCrops] ItemDisplay not exists: " + id); - entity.remove(); + OraxenFurniture.remove(entity, null); return null; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/Action.java b/src/main/java/net/momirealms/customcrops/api/object/action/Action.java index 82d4a82..9c07cf3 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/Action.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/Action.java @@ -24,6 +24,6 @@ import org.jetbrains.annotations.Nullable; public interface Action { - void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode); + void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java index 02d6a2e..7f34a28 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/BreakImpl.java @@ -24,10 +24,14 @@ import net.momirealms.customcrops.api.object.crop.CropConfig; import net.momirealms.customcrops.api.object.crop.StageConfig; import net.momirealms.customcrops.api.object.world.SimpleLocation; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.concurrent.CompletableFuture; + public class BreakImpl implements Action { private final boolean triggerAction; @@ -39,30 +43,57 @@ public class BreakImpl implements Action { } @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { - if (crop_loc == null || stage_id == null || player == null) return; + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { + if (cropLoc == null || stage_id == null) return; CropConfig cropConfig = CustomCrops.getInstance().getCropManager().getCropConfigByStage(stage_id); - CustomCrops.getInstance().getScheduler().runTask(() -> { - Location bLoc = crop_loc.getBukkitLocation(); - if (bLoc == null) return; + Location bLoc = cropLoc.getBukkitLocation(); + if (bLoc == null) return; + if (player != null) { CropBreakEvent cropBreakEvent = new CropBreakEvent(player, cropConfig, stage_id, bLoc); Bukkit.getPluginManager().callEvent(cropBreakEvent); if (cropBreakEvent.isCancelled()) { return; } CustomCrops.getInstance().getPlatformInterface().removeAnyThingAt(bLoc); - CustomCrops.getInstance().getWorldDataManager().removeCropData(crop_loc); - if (triggerAction) { - StageConfig stageConfig = CustomCrops.getInstance().getCropManager().getStageConfig(stage_id); - if (stageConfig != null) { - Action[] actions = stageConfig.getBreakActions(); - if (actions != null) { - for (Action action : actions) { - action.doOn(player, crop_loc, itemMode); - } + CustomCrops.getInstance().getWorldDataManager().removeCropData(cropLoc); + doTriggerActions(player, cropLoc, itemMode); + } else { + CompletableFuture asyncGetChunk = bLoc.getWorld().getChunkAtAsync(bLoc.getBlockX() >> 4, bLoc.getBlockZ() >> 4); + if (itemMode == ItemMode.ITEM_FRAME || itemMode == ItemMode.ITEM_DISPLAY) { + CompletableFuture loadEntities = asyncGetChunk.thenApply((chunk) -> { + chunk.getEntities(); + return chunk.isEntitiesLoaded(); + }); + loadEntities.whenComplete((result, throwable) -> + CustomCrops.getInstance().getScheduler().runTask(() -> { + CustomCrops.getInstance().getWorldDataManager().removeCropData(cropLoc); + if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(bLoc, itemMode)) { + doTriggerActions(null, cropLoc, itemMode); + } + })); + } else { + asyncGetChunk.whenComplete((result, throwable) -> + CustomCrops.getInstance().getScheduler().runTask(() -> { + CustomCrops.getInstance().getWorldDataManager().removeCropData(cropLoc); + if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(bLoc, itemMode)) { + doTriggerActions(null, cropLoc, itemMode); + } + })); + } + } + } + + private void doTriggerActions(@Nullable Player player, @NotNull SimpleLocation crop_loc, ItemMode itemMode) { + if (triggerAction) { + StageConfig stageConfig = CustomCrops.getInstance().getCropManager().getStageConfig(stage_id); + if (stageConfig != null) { + Action[] actions = stageConfig.getBreakActions(); + if (actions != null) { + for (Action action : actions) { + action.doOn(player, crop_loc, itemMode); } } } - }); + } } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java index 37cfd2b..9cb59c4 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/ChainImpl.java @@ -33,10 +33,10 @@ public class ChainImpl implements Action { } @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (Math.random() < chance) { for (Action action : actions) { - action.doOn(player, crop_loc, itemMode); + action.doOn(player, cropLoc, itemMode); } } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/CommandActionImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/CommandActionImpl.java index e929322..381f117 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/CommandActionImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/CommandActionImpl.java @@ -26,14 +26,14 @@ import org.jetbrains.annotations.Nullable; public record CommandActionImpl(String[] commands, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null || Math.random() > chance) return; for (String command : commands) { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()) - .replace("{x}", crop_loc == null ? "" : String.valueOf(crop_loc.getX())) - .replace("{y}", crop_loc == null ? "" : String.valueOf(crop_loc.getY())) - .replace("{z}", crop_loc == null ? "" : String.valueOf(crop_loc.getZ())) + .replace("{x}", cropLoc == null ? "" : String.valueOf(cropLoc.getX())) + .replace("{y}", cropLoc == null ? "" : String.valueOf(cropLoc.getY())) + .replace("{z}", cropLoc == null ? "" : String.valueOf(cropLoc.getZ())) .replace("{world}", player.getWorld().getName()) ); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java index ae1bd2c..fa2a451 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/DropItemImpl.java @@ -17,6 +17,7 @@ package net.momirealms.customcrops.api.object.action; +import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.loot.Loot; import net.momirealms.customcrops.api.object.world.SimpleLocation; @@ -26,10 +27,18 @@ import org.jetbrains.annotations.Nullable; public record DropItemImpl(Loot[] loots) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { - if (crop_loc == null) return; - for (Loot loot : loots) { - loot.drop(player, crop_loc.getBukkitLocation()); + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { + if (cropLoc == null) return; + if (player != null) { + for (Loot loot : loots) { + loot.drop(player, cropLoc.getBukkitLocation()); + } + } else { + CustomCrops.getInstance().getScheduler().runTask(() -> { + for (Loot loot : loots) { + loot.drop(null, cropLoc.getBukkitLocation()); + } + }); } } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/GiveMoneyImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/GiveMoneyImpl.java index 26d7e72..f050014 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/GiveMoneyImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/GiveMoneyImpl.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable; public record GiveMoneyImpl(double money, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player != null && Math.random() < chance) { VaultHook vaultHook = CustomCrops.getInstance().getIntegrationManager().getVault(); if (vaultHook != null) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java index 2fa7938..0ddf8d5 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/JobXPImpl.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable; public record JobXPImpl(double amount, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null || Math.random() > chance) return; JobInterface jobInterface = CustomCrops.getInstance().getIntegrationManager().getJobInterface(); if (jobInterface == null) return; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/MessageActionImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/MessageActionImpl.java index 0c603b7..b5e06e6 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/MessageActionImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/MessageActionImpl.java @@ -26,15 +26,15 @@ import org.jetbrains.annotations.Nullable; public record MessageActionImpl(String[] messages, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null || Math.random() > chance) return; for (String message : messages) { AdventureUtils.playerMessage(player, message.replace("{player}", player.getName()) .replace("{world}", player.getWorld().getName()) - .replace("{x}", crop_loc == null ? "" : String.valueOf(crop_loc.getX())) - .replace("{y}", crop_loc == null ? "" : String.valueOf(crop_loc.getY())) - .replace("{z}", crop_loc == null ? "" : String.valueOf(crop_loc.getZ())) + .replace("{x}", cropLoc == null ? "" : String.valueOf(cropLoc.getX())) + .replace("{y}", cropLoc == null ? "" : String.valueOf(cropLoc.getY())) + .replace("{z}", cropLoc == null ? "" : String.valueOf(cropLoc.getZ())) ); } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java index 72c812a..05f216f 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/ParticleImpl.java @@ -37,9 +37,9 @@ public class ParticleImpl implements Action { } @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { - if (crop_loc == null) return; - Location location = crop_loc.getBukkitLocation(); + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { + if (cropLoc == null) return; + Location location = cropLoc.getBukkitLocation(); if (location == null) return; location.getWorld().spawnParticle(particle, location.clone().add(0.5,0.5,0.5), amount, offset, offset, offset); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/PotionEffectImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/PotionEffectImpl.java index da27c9c..317dd87 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/PotionEffectImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/PotionEffectImpl.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; public record PotionEffectImpl(PotionEffect potionEffect, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null || Math.random() > chance) return; player.addPotionEffect(potionEffect); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java index 6b57ef6..919f26d 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/ReplantImpl.java @@ -27,10 +27,13 @@ import net.momirealms.customcrops.api.object.crop.GrowingCrop; import net.momirealms.customcrops.api.object.world.SimpleLocation; import net.momirealms.customcrops.api.util.AdventureUtils; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; +import java.util.concurrent.CompletableFuture; + public class ReplantImpl implements Action { private final int point; @@ -44,30 +47,56 @@ public class ReplantImpl implements Action { } @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { - if (player == null || crop_loc == null) return; + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { + if (cropLoc == null) return; CropConfig cropConfig = CustomCrops.getInstance().getCropManager().getCropConfigByID(crop); if (cropConfig != null) { + Location location = cropLoc.getBukkitLocation(); + if (location == null) return; ItemMode newCMode = cropConfig.getCropMode(); - CustomCrops.getInstance().getScheduler().runTask(() -> { - Location location = crop_loc.getBukkitLocation(); - if (location == null) return; - if (ConfigManager.enableLimitation && CustomCrops.getInstance().getWorldDataManager().getChunkCropAmount(crop_loc) >= ConfigManager.maxCropPerChunk) { - AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit); - return; + if (ConfigManager.enableLimitation && CustomCrops.getInstance().getWorldDataManager().getChunkCropAmount(cropLoc) >= ConfigManager.maxCropPerChunk) { + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit); + return; + } + if (player != null) { + // Though the task is executed on main thread + // But it still needs slight delay to prevent crop loots from doubled when clicking with both left and right click + // It's still unsure how it happens + CustomCrops.getInstance().getScheduler().runTask(() -> { + CropPlantEvent cropPlantEvent = new CropPlantEvent(player, player.getInventory().getItemInMainHand(), location, crop, point, model); + Bukkit.getPluginManager().callEvent(cropPlantEvent); + if (cropPlantEvent.isCancelled()) { + return; + } + if (!CustomCrops.getInstance().getPlatformInterface().detectAnyThing(location)) { + CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, model, newCMode); + CustomCrops.getInstance().getWorldDataManager().addCropData(cropLoc, new GrowingCrop(crop, point), true); + } + }); + } else { + CompletableFuture asyncGetChunk = location.getWorld().getChunkAtAsync(location.getBlockX() >> 4, location.getBlockZ() >> 4); + if (itemMode == ItemMode.ITEM_FRAME || itemMode == ItemMode.ITEM_DISPLAY) { + CompletableFuture loadEntities = asyncGetChunk.thenApply((chunk) -> { + chunk.getEntities(); + return chunk.isEntitiesLoaded(); + }); + loadEntities.whenComplete((result, throwable) -> + CustomCrops.getInstance().getScheduler().runTask(() -> { + if (!CustomCrops.getInstance().getPlatformInterface().detectAnyThing(location)) { + CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, model, newCMode); + CustomCrops.getInstance().getWorldDataManager().addCropData(cropLoc, new GrowingCrop(crop, point), true); + } + })); + } else { + asyncGetChunk.whenComplete((result, throwable) -> + CustomCrops.getInstance().getScheduler().runTask(() -> { + if (!CustomCrops.getInstance().getPlatformInterface().detectAnyThing(location)) { + CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, model, newCMode); + CustomCrops.getInstance().getWorldDataManager().addCropData(cropLoc, new GrowingCrop(crop, point), true); + } + })); } - - CropPlantEvent cropPlantEvent = new CropPlantEvent(player, player.getInventory().getItemInMainHand(), location, crop, point, model); - Bukkit.getPluginManager().callEvent(cropPlantEvent); - if (cropPlantEvent.isCancelled()) { - return; - } - - if (!CustomCrops.getInstance().getPlatformInterface().detectAnyThing(location)) { - CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, model, newCMode); - CustomCrops.getInstance().getWorldDataManager().addCropData(crop_loc, new GrowingCrop(crop, point), true); - } - }); + } } } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/SkillXPImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/SkillXPImpl.java index 580a01b..cb7f11f 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/SkillXPImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/SkillXPImpl.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable; public record SkillXPImpl(double amount, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null || Math.random() > chance) return; SkillInterface skillInterface = CustomCrops.getInstance().getIntegrationManager().getSkillInterface(); if (skillInterface == null) return; diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/SoundActionImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/SoundActionImpl.java index 98c5825..a995bfa 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/SoundActionImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/SoundActionImpl.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; public record SoundActionImpl(String source, String sound, float volume, float pitch) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null) return; AdventureUtils.playerSound(player, Sound.Source.valueOf(source.toUpperCase()), Key.key(sound), volume, pitch); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/SwingHandImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/SwingHandImpl.java index 93bb483..73c9146 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/SwingHandImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/SwingHandImpl.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable; public class SwingHandImpl implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player != null) { player.swingMainHand(); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/VanillaXPImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/VanillaXPImpl.java index d4a8e12..da008f7 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/VanillaXPImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/VanillaXPImpl.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable; public record VanillaXPImpl(int amount, boolean mending, double chance) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { if (player == null || Math.random() > chance) return; player.giveExp(amount, mending); AdventureUtils.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); diff --git a/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java b/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java index 72552fd..a16cd37 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/action/VariationImpl.java @@ -34,16 +34,16 @@ import java.util.concurrent.CompletableFuture; public record VariationImpl(VariationCrop[] variationCrops) implements Action { @Override - public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) { - if (crop_loc == null) return; + public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) { + if (cropLoc == null) return; double bonus = 0; - Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(crop_loc.add(0,-1,0)); + Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(cropLoc.add(0,-1,0)); if (pot != null && CustomCrops.getInstance().getFertilizerManager().getConfigByFertilizer(pot.getFertilizer()) instanceof Variation variation) { bonus = variation.getChance(); } for (VariationCrop variationCrop : variationCrops) { if (Math.random() < variationCrop.getChance() + bonus) { - doVariation(crop_loc, itemMode, variationCrop); + doVariation(cropLoc, itemMode, variationCrop); break; } } @@ -81,8 +81,7 @@ public record VariationImpl(VariationCrop[] variationCrops) implements Action { } return null; })); - } - else { + } else { asyncGetChunk.whenComplete((result, throwable) -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(location, itemMode)) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java b/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java index f10d1b4..9563452 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java +++ b/src/main/java/net/momirealms/customcrops/api/object/loot/Loot.java @@ -24,6 +24,7 @@ import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.concurrent.ThreadLocalRandom; @@ -37,7 +38,7 @@ public abstract class Loot { this.max = max; } - public void drop(Player player, Location location) { + public void drop(@Nullable Player player, Location location) { //empty } @@ -49,7 +50,7 @@ public abstract class Loot { return max; } - public int getAmount(Player player) { + public int getAmount(@Nullable Player player) { int random = ThreadLocalRandom.current().nextInt(getMin(), getMax() + 1); if (ConfigManager.enableSkillBonus && player != null) { SkillInterface skillInterface = CustomCrops.getInstance().getIntegrationManager().getSkillInterface(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2e6f64f..c556a6e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -25,13 +25,13 @@ schedule-system: enable: true # The average interval for a crop to gain one point (measured in seconds) # 平均每个农作物获得一生长点的时间间隔(秒) - point-gain-interval: 300 - # Water amount and fertilizer would reduce every 4 points are gained + point-gain-interval: 400 + # Water amount and fertilizer would reduce every 3 points are gained # set it to -1 if you don't want CustomCrops to control consumption/sprinkler tasks - # 默认每四个生长点进行一次水分、肥料消耗/洒水器工作 + # 默认每3个生长点进行一次水分、肥料消耗 # 设置为-1以禁用CustomCrops对水分、肥料消耗/洒水器任务的掌管 - consume-water-fertilizer-every-x-point: 4 - # Sprinkler would work every two points are gained + consume-water-fertilizer-every-x-point: 3 + # Sprinkler would work every 2 points are gained sprinkler-work-every-x-point: 2 # Save cache to file interval (seconds) # set "-1" to disable