diff --git a/build.gradle.kts b/build.gradle.kts index 8491126..1a447b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { project.group = "net.momirealms" - project.version = "3.3.1.3" + project.version = "3.3.1.4" apply() apply(plugin = "java") diff --git a/plugin/src/main/java/net/momirealms/customcrops/api/object/requirement/LightLevelImpl.java b/plugin/src/main/java/net/momirealms/customcrops/api/object/requirement/LightLevelImpl.java new file mode 100644 index 0000000..a4379f2 --- /dev/null +++ b/plugin/src/main/java/net/momirealms/customcrops/api/object/requirement/LightLevelImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object.requirement; + +import net.momirealms.customcrops.api.object.action.Action; +import org.jetbrains.annotations.Nullable; + +public class LightLevelImpl extends AbstractRequirement implements Requirement { + + private final int level; + + public LightLevelImpl(@Nullable String[] msg, @Nullable Action[] actions, int level) { + super(msg, actions); + this.level = level; + } + + @Override + public boolean isConditionMet(CurrentState currentState) { + if (currentState.getLocation().getBlock().getLightLevel() >= level) { + return true; + } + notMetActions(currentState); + return false; + } +} diff --git a/plugin/src/main/java/net/momirealms/customcrops/api/object/requirement/NaturalLightLevelImpl.java b/plugin/src/main/java/net/momirealms/customcrops/api/object/requirement/NaturalLightLevelImpl.java new file mode 100644 index 0000000..b307c00 --- /dev/null +++ b/plugin/src/main/java/net/momirealms/customcrops/api/object/requirement/NaturalLightLevelImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.object.requirement; + +import net.momirealms.customcrops.api.object.action.Action; +import org.jetbrains.annotations.Nullable; + +public class NaturalLightLevelImpl extends AbstractRequirement implements Requirement { + + private final int level; + + public NaturalLightLevelImpl(@Nullable String[] msg, @Nullable Action[] actions, int level) { + super(msg, actions); + this.level = level; + } + + @Override + public boolean isConditionMet(CurrentState currentState) { + if (currentState.getLocation().getBlock().getLightFromSky() >= level) { + return true; + } + notMetActions(currentState); + return false; + } +} diff --git a/plugin/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java b/plugin/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java index 7d0be7e..2a88caf 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java +++ b/plugin/src/main/java/net/momirealms/customcrops/api/object/world/WorldListener.java @@ -17,8 +17,6 @@ package net.momirealms.customcrops.api.object.world; -import net.momirealms.customcrops.api.event.CropBreakEvent; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.ChunkLoadEvent; diff --git a/plugin/src/main/java/net/momirealms/customcrops/customplugin/PlatformManager.java b/plugin/src/main/java/net/momirealms/customcrops/customplugin/PlatformManager.java index 2c9df11..00172e1 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/customplugin/PlatformManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/customplugin/PlatformManager.java @@ -734,27 +734,36 @@ public class PlatformManager extends Function { if (cropPlantEvent.isCancelled()) return true; - Action[] plantActions = cropConfig.getPlantActions(); - if (plantActions != null) { - for (Action action : plantActions) { - action.doOn(player, SimpleLocation.getByBukkitLocation(crop_loc), cropConfig.getCropMode()); - } - } - - if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1); - player.swingMainHand(); switch (cropConfig.getCropMode()) { case ITEM_DISPLAY -> { ItemDisplay itemDisplay = CustomCrops.getInstance().getPlatformInterface().placeItemDisplay(crop_loc, cropPlantEvent.getCropModel()); - if (itemDisplay != null && cropConfig.isRotationEnabled()) itemDisplay.setRotation(RotationUtils.getRandomFloatRotation(), itemDisplay.getLocation().getPitch()); + if (itemDisplay == null) + return true; + if (cropConfig.isRotationEnabled()) + itemDisplay.setRotation(RotationUtils.getRandomFloatRotation(), itemDisplay.getLocation().getPitch()); } case ITEM_FRAME -> { ItemFrame itemFrame = CustomCrops.getInstance().getPlatformInterface().placeItemFrame(crop_loc, cropPlantEvent.getCropModel()); - if (itemFrame != null && cropConfig.isRotationEnabled()) itemFrame.setRotation(RotationUtils.getRandomRotation()); + if (itemFrame == null) + return true; + if (cropConfig.isRotationEnabled()) + itemFrame.setRotation(RotationUtils.getRandomRotation()); } case TRIPWIRE -> CustomCrops.getInstance().getPlatformInterface().placeTripWire(crop_loc, cropPlantEvent.getCropModel()); } + Action[] plantActions = cropConfig.getPlantActions(); + if (plantActions != null) { + for (Action action : plantActions) { + action.doOn( + player, + SimpleLocation.getByBukkitLocation(crop_loc), + cropConfig.getCropMode() + ); + } + } + player.swingMainHand(); + if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1); plugin.getWorldDataManager().addCropData(SimpleLocation.getByBukkitLocation(crop_loc), new GrowingCrop(cropConfig.getKey(), cropPlantEvent.getPoint()), true); return true; } diff --git a/plugin/src/main/java/net/momirealms/customcrops/customplugin/itemsadder/ItemsAdderPluginImpl.java b/plugin/src/main/java/net/momirealms/customcrops/customplugin/itemsadder/ItemsAdderPluginImpl.java index f4b428e..e706e6f 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/customplugin/itemsadder/ItemsAdderPluginImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/customplugin/itemsadder/ItemsAdderPluginImpl.java @@ -67,7 +67,9 @@ public class ItemsAdderPluginImpl implements PlatformInterface { if (entity instanceof ItemFrame itemFrame) return itemFrame; else { - AdventureUtils.consoleMessage("[CustomCrops] ItemFrame not exists: " + id); + AdventureUtils.consoleMessage("[CustomCrops] ItemFrame not placed: " + id + ". " + + "If you are sure that you are using the right item type, " + + "please set max max-furniture-vehicles-per-chunk to a higher value in IA config.yml."); customFurniture.remove(false); } return null; @@ -85,7 +87,9 @@ public class ItemsAdderPluginImpl implements PlatformInterface { if (entity instanceof ItemDisplay itemDisplay) return itemDisplay; else { - AdventureUtils.consoleMessage("[CustomCrops] ItemDisplay not exists: " + id); + AdventureUtils.consoleMessage("[CustomCrops] ItemFrame not placed: " + id + ". " + + "If you are sure that you are using the right item type, " + + "please set max max-furniture-vehicles-per-chunk to a higher value in IA config.yml."); customFurniture.remove(false); } return null; diff --git a/plugin/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java b/plugin/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java index 732642a..d35f19c 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java @@ -178,13 +178,17 @@ public class IntegrationManager extends Function { if (pluginManager.isPluginEnabled("ClueScrolls")) { ClueScrollCCQuest quest = new ClueScrollCCQuest(plugin); Bukkit.getPluginManager().registerEvents(quest, plugin); + hookMessage("ClueScrolls"); } if (pluginManager.isPluginEnabled("BetonQuest")) { if (Bukkit.getPluginManager().getPlugin("BetonQuest").getDescription().getVersion().startsWith("2")) BetonQuestCCQuest.register(); else LegacyBetonQuestCCQuest.register(); + hookMessage("BetonQuest"); } if (pluginManager.isPluginEnabled("BattlePass")) { - BattlePassCCQuest.register(); + BattlePassCCQuest battlePassCCQuest = new BattlePassCCQuest(); + Bukkit.getPluginManager().registerEvents(battlePassCCQuest, plugin); + hookMessage("BattlePass"); } } diff --git a/plugin/src/main/java/net/momirealms/customcrops/integration/quest/BattlePassCCQuest.java b/plugin/src/main/java/net/momirealms/customcrops/integration/quest/BattlePassCCQuest.java index fb69e22..0a74bf2 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/integration/quest/BattlePassCCQuest.java +++ b/plugin/src/main/java/net/momirealms/customcrops/integration/quest/BattlePassCCQuest.java @@ -18,7 +18,8 @@ package net.momirealms.customcrops.integration.quest; import io.github.battlepass.BattlePlugin; -import io.github.battlepass.quests.quests.external.executor.ExternalQuestExecutor; +import io.github.battlepass.api.events.server.PluginReloadEvent; +import io.github.battlepass.quests.service.base.ExternalQuestContainer; import io.github.battlepass.registry.quest.QuestRegistry; import net.momirealms.customcrops.api.event.CropBreakEvent; import net.momirealms.customcrops.api.event.CropPlantEvent; @@ -26,31 +27,49 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -public class BattlePassCCQuest extends ExternalQuestExecutor implements Listener { +public class BattlePassCCQuest implements Listener { public static void register() { QuestRegistry questRegistry = BattlePlugin.getApi().getQuestRegistry(); - questRegistry.hook("customcrops", BattlePassCCQuest::new); + questRegistry.hook("customcrops", CropQuest::new); } - public BattlePassCCQuest(BattlePlugin battlePlugin) { - super(battlePlugin, "customcrops"); + @EventHandler(ignoreCancelled = true) + public void onBattlePassReload(PluginReloadEvent event) { + register(); } - @EventHandler - public void onHarvest(CropBreakEvent event) { - if (event.isCancelled()) return; - if (event.getEntity() instanceof Player player) { - String id = event.getCropItemID(); - String[] split = id.split(":"); - this.execute("harvest", player, (result) -> result.root(split[split.length - 1])); + private static class CropQuest extends ExternalQuestContainer { + + public CropQuest(BattlePlugin battlePlugin) { + super(battlePlugin, "customcrops"); + } + + @EventHandler + public void onHarvest(CropBreakEvent event) { + if (event.isCancelled()) + return; + if (event.getEntity() instanceof Player player) { + String id = event.getCropItemID(); + String[] split = id.split(":"); + this.executionBuilder("harvest") + .player(player) + .root(split[split.length - 1]) + .progress(1) + .buildAndExecute(); + } + } + + @EventHandler + public void onPlant(CropPlantEvent event) { + if (event.isCancelled()) + return; + String id = event.getCropKey(); + this.executionBuilder("plant") + .player(event.getPlayer()) + .root(id) + .progress(1) + .buildAndExecute(); } } - - @EventHandler - public void onPlant(CropPlantEvent event) { - if (event.isCancelled()) return; - String id = event.getCropKey(); - this.execute("plant", event.getPlayer(), (result) -> result.root(id)); - } } \ No newline at end of file diff --git a/plugin/src/main/java/net/momirealms/customcrops/integration/skill/MMOCoreImpl.java b/plugin/src/main/java/net/momirealms/customcrops/integration/skill/MMOCoreImpl.java index 9ee5596..ae1dcb9 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/integration/skill/MMOCoreImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/integration/skill/MMOCoreImpl.java @@ -18,11 +18,9 @@ package net.momirealms.customcrops.integration.skill; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.MMOCoreAPI; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.Profession; -import net.Indyuce.mmocore.manager.data.PlayerDataManager; import net.momirealms.customcrops.integration.SkillInterface; import org.bukkit.entity.Player; diff --git a/plugin/src/main/java/net/momirealms/customcrops/util/ConfigUtils.java b/plugin/src/main/java/net/momirealms/customcrops/util/ConfigUtils.java index 961645b..0ea609e 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/util/ConfigUtils.java +++ b/plugin/src/main/java/net/momirealms/customcrops/util/ConfigUtils.java @@ -219,6 +219,8 @@ public class ConfigUtils { case "time" -> requirements.add(new TimeImpl(msg, getActions(actionSec), innerSec.getStringList("value"))); case "skill-level" -> requirements.add(new SkillLevelImpl(msg, getActions(actionSec), innerSec.getInt("value"))); case "job-level" -> requirements.add(new JobLevelImpl(msg, getActions(actionSec), innerSec.getInt("value.level"), innerSec.getString("value.job"))); + case "light" -> requirements.add(new LightLevelImpl(msg, getActions(actionSec), innerSec.getInt("value"))); + case "natural-light" -> requirements.add(new NaturalLightLevelImpl(msg, getActions(actionSec), innerSec.getInt("value"))); case "date" -> requirements.add(new DateImpl(msg, getActions(actionSec), new HashSet<>(innerSec.getStringList("value")))); case "max-entity-amount-in-chunk" -> requirements.add(new EntityAmountInChunkImpl(msg, getActions(actionSec), innerSec.getInt("value"))); case "papi-condition" -> requirements.add(new CustomPapi(msg, getActions(actionSec), Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false)));