mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Merge branch 'master' of http://Indyuce@dev.lumine.io/bitbucket/scm/mmo/mmocore.git
This commit is contained in:
commit
ba164288b1
@ -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