Removed 'harvestcrop', replaced with option in 'mineblock'

This commit is contained in:
Aria 2019-09-12 01:02:49 +02:00
parent ea48b9616b
commit efc387d7a2
4 changed files with 9 additions and 64 deletions

View File

@ -1,56 +0,0 @@
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

@ -8,6 +8,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
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;
@ -17,6 +18,7 @@ import net.Indyuce.mmocore.manager.profession.ExperienceManager;
public class MineBlockExperienceSource extends SpecificExperienceSource<Material> {
private final Material material;
private final boolean silkTouch;
private final boolean crop;
public MineBlockExperienceSource(Profession profession, MMOLineConfig config) {
super(profession, config);
@ -24,6 +26,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
config.validate("type");
material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
silkTouch = config.getBoolean("silk-touch", true);
crop = config.getBoolean("crop", false);
}
@Override
@ -37,7 +40,9 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
if (silkTouch && hasSilkTouch(event.getPlayer().getInventory().getItemInMainHand()))
return;
if (crop && !MMOCore.plugin.version.getVersionWrapper().isCropFullyGrown(event.getBlock()))
return;
Material broken = event.getBlock().getType();
PlayerData data = PlayerData.get(event.getPlayer());

View File

@ -13,7 +13,6 @@ 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,9 +112,6 @@ 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:
- 'harvestcrop{type=CARROTS;amount=1-3}'
- 'harvestcrop{type=POTATOES;amount=1-3}'
- 'harvestcrop{type=WHEAT;amount=1-3}'
- 'mineblock{type=CARROTS;amount=1-3;crop=true}'
- 'mineblock{type=POTATOES;amount=1-3;crop=true}'
- 'mineblock{type=WHEAT;amount=1-3;crop=true}'