Added placeblock experience source

This commit is contained in:
Aria 2019-10-19 19:07:05 +02:00
parent ebc72693e8
commit 9abb792df3
2 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,47 @@
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.BlockPlaceEvent;
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 PlaceBlockExperienceSource extends SpecificExperienceSource<Material> {
public final Material material;
public PlaceBlockExperienceSource(Profession profession, MMOLineConfig config) {
super(profession, config);
config.validate("type");
material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
}
@Override
public ExperienceManager<PlaceBlockExperienceSource> newManager() {
return new ExperienceManager<PlaceBlockExperienceSource>() {
@EventHandler(priority = EventPriority.HIGHEST)
public void a(BlockPlaceEvent event) {
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.SURVIVAL)
return;
PlayerData data = PlayerData.get(event.getPlayer());
for (PlaceBlockExperienceSource source : getSources()) {
if (source.matches(data, event.getBlock().getType()))
source.giveExperience(data);
}
}
};
}
@Override
public boolean matches(PlayerData player, Material obj) {
return material == obj && hasRightClass(player);
}
}

View File

@ -16,6 +16,7 @@ import net.Indyuce.mmocore.api.experience.source.EnchantItemExperienceSource;
import net.Indyuce.mmocore.api.experience.source.FishItemExperienceSource;
import net.Indyuce.mmocore.api.experience.source.KillMobExperienceSource;
import net.Indyuce.mmocore.api.experience.source.MineBlockExperienceSource;
import net.Indyuce.mmocore.api.experience.source.PlaceBlockExperienceSource;
import net.Indyuce.mmocore.api.experience.source.RepairItemExperienceSource;
import net.Indyuce.mmocore.api.experience.source.SmeltItemExperienceSource;
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
@ -88,7 +89,7 @@ public class DefaultMMOLoader implements MMOLoader {
if (config.getKey().equals("mineblock"))
return new MineBlockObjective(section, config);
if (config.getKey().equals("killmob"))
return new KillMobObjective(section, config);
@ -117,6 +118,9 @@ public class DefaultMMOLoader implements MMOLoader {
if (config.getKey().equals("mineblock"))
return new MineBlockExperienceSource(profession, config);
if (config.getKey().equals("placeblock"))
return new PlaceBlockExperienceSource(profession, config);
if (config.getKey().equals("brewpotion"))
return new BrewPotionExperienceSource(profession, config);