Added 'harvestcrop' exp source

This commit is contained in:
Aria 2019-09-12 00:54:52 +02:00
parent 02277d30ff
commit 0edbbd977a
3 changed files with 63 additions and 3 deletions

View File

@ -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<Material> {
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<HarvestCropExperienceSource> newManager() {
return new ExperienceManager<HarvestCropExperienceSource>() {
@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);
}
}

View File

@ -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);

View File

@ -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}'