diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/HarvestCropExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/HarvestCropExperienceSource.java new file mode 100644 index 00000000..ccce02e5 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/HarvestCropExperienceSource.java @@ -0,0 +1,56 @@ +package net.Indyuce.mmocore.api.experience.source; + +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; + +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.api.load.MMOLineConfig; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceManager; + +public class HarvestCropExperienceSource extends SpecificExperienceSource { + private final Material material; + private final boolean ripe; + + public HarvestCropExperienceSource(Profession profession, MMOLineConfig config) { + super(profession, config); + + config.validate("type"); + material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + ripe = config.getBoolean("ripe", true); + } + + @Override + public ExperienceManager newManager() { + return new ExperienceManager() { + + @EventHandler(priority = EventPriority.HIGHEST) + public void a(BlockBreakEvent event) { + if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.SURVIVAL) + return; + + + + if (ripe && !MMOCore.plugin.version.getVersionWrapper().isCropFullyGrown(event.getBlock())) + return; + + Material broken = event.getBlock().getType(); + + PlayerData data = PlayerData.get(event.getPlayer()); + for (HarvestCropExperienceSource source : getSources()) + if (source.matches(data, broken)) + source.giveExperience(data); + } + }; + } + + @Override + public boolean matches(PlayerData player, Material obj) { + return material == obj && hasRightClass(player); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index fcb1c826..add0b986 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -13,6 +13,7 @@ import net.Indyuce.mmocore.api.experience.Profession; import net.Indyuce.mmocore.api.experience.source.BrewPotionExperienceSource; import net.Indyuce.mmocore.api.experience.source.EnchantItemExperienceSource; import net.Indyuce.mmocore.api.experience.source.FishItemExperienceSource; +import net.Indyuce.mmocore.api.experience.source.HarvestCropExperienceSource; import net.Indyuce.mmocore.api.experience.source.KillMobExperienceSource; import net.Indyuce.mmocore.api.experience.source.MineBlockExperienceSource; import net.Indyuce.mmocore.api.experience.source.RepairItemExperienceSource; @@ -113,6 +114,9 @@ public class DefaultMMOLoader implements MMOLoader { if (config.getKey().equals("mineblock")) return new MineBlockExperienceSource(profession, config); + if (config.getKey().equals("harvestcrop")) + return new HarvestCropExperienceSource(profession, config); + if (config.getKey().equals("brewpotion")) return new BrewPotionExperienceSource(profession, config); diff --git a/src/main/resources/default/professions/farming.yml b/src/main/resources/default/professions/farming.yml index 3ec12fd6..08b2b223 100644 --- a/src/main/resources/default/professions/farming.yml +++ b/src/main/resources/default/professions/farming.yml @@ -9,6 +9,6 @@ experience: per-level: 2 exp-sources: -- 'mineblock{type=CARROTS;amount=1-3}' -- 'mineblock{type=POTATOES;amount=1-3}' -- 'mineblock{type=WHEAT;amount=1-3}' +- 'harvestcrop{type=CARROTS;amount=1-3}' +- 'harvestcrop{type=POTATOES;amount=1-3}' +- 'harvestcrop{type=WHEAT;amount=1-3}'