forked from Upstream/mmocore
Added 'craftitem' XP source.
(Syntax is the same as mineblock)
This commit is contained in:
parent
280b48b857
commit
f33f55491b
@ -0,0 +1,46 @@
|
||||
package net.Indyuce.mmocore.api.experience.source;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
|
||||
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 CraftItemExperienceSource extends SpecificExperienceSource<Material> {
|
||||
public final Material material;
|
||||
|
||||
public CraftItemExperienceSource(Profession profession, MMOLineConfig config) {
|
||||
super(profession, config);
|
||||
|
||||
config.validate("type");
|
||||
material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceManager<CraftItemExperienceSource> newManager() {
|
||||
return new ExperienceManager<CraftItemExperienceSource>() {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void a(CraftItemEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
PlayerData data = PlayerData.get((Player) event.getWhoClicked());
|
||||
for (CraftItemExperienceSource source : getSources())
|
||||
if (source.matches(data, event.getInventory().getResult().getType()))
|
||||
source.giveExperience(data, event.getInventory().getLocation());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(PlayerData player, Material obj) {
|
||||
return material == obj && hasRightClass(player);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import net.Indyuce.mmocore.api.droptable.dropitem.NoteDropItem;
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.VanillaDropItem;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.experience.source.BrewPotionExperienceSource;
|
||||
import net.Indyuce.mmocore.api.experience.source.CraftItemExperienceSource;
|
||||
import net.Indyuce.mmocore.api.experience.source.EnchantItemExperienceSource;
|
||||
import net.Indyuce.mmocore.api.experience.source.FishItemExperienceSource;
|
||||
import net.Indyuce.mmocore.api.experience.source.KillMobExperienceSource;
|
||||
@ -133,6 +134,9 @@ public class DefaultMMOLoader implements MMOLoader {
|
||||
if (config.getKey().equals("repairitem"))
|
||||
return new RepairItemExperienceSource(profession, config);
|
||||
|
||||
if (config.getKey().equals("craftitem"))
|
||||
return new CraftItemExperienceSource(profession, config);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user