Fixed exp sources

This commit is contained in:
Aria 2019-09-13 01:35:30 +02:00
parent a0f05957f8
commit c98a952261
7 changed files with 26 additions and 19 deletions

View File

@ -49,9 +49,9 @@ public class EnchantItemExperienceSource extends ExperienceSource<Void> {
if (source.matches(player, null)) {
Map<Enchantment, Integer> ench = new HashMap<>(event.getEnchantsToAdd());
if (!enchants.isEmpty())
if (!source.enchants.isEmpty())
for (Iterator<Enchantment> iterator = ench.keySet().iterator(); iterator.hasNext();)
if (!enchants.contains(iterator.next()))
if (!source.enchants.contains(iterator.next()))
iterator.remove();
if (ench.isEmpty())

View File

@ -13,7 +13,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
private final EntityType type;
public final EntityType type;
public KillMobExperienceSource(Profession profession, MMOLineConfig config) {
super(profession, config);
@ -30,6 +30,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
public void a(EntityKillEntityEvent event) {
if (event.getEntity() instanceof Player) {
PlayerData data = PlayerData.get((Player) event.getEntity());
for (KillMobExperienceSource source : getSources())
if (source.matches(data, event.getTarget()))
source.giveExperience(data);

View File

@ -16,9 +16,10 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceManager;
public class MineBlockExperienceSource extends SpecificExperienceSource<Material> {
private final Material material;
public final Material material;
private final boolean silkTouch;
private final boolean crop;
private final boolean playerPlaced;
public MineBlockExperienceSource(Profession profession, MMOLineConfig config) {
super(profession, config);
@ -27,6 +28,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
silkTouch = config.getBoolean("silk-touch", true);
crop = config.getBoolean("crop", false);
playerPlaced = config.getBoolean("player-placed", false);
}
@Override
@ -37,18 +39,20 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
public void a(BlockBreakEvent event) {
if (event.isCancelled() || event.getPlayer().getGameMode() != GameMode.SURVIVAL)
return;
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());
for (MineBlockExperienceSource source : getSources())
if (source.matches(data, broken))
{
if (source.silkTouch && hasSilkTouch(event.getPlayer().getInventory().getItemInMainHand()))
continue;
if (source.crop && !MMOCore.plugin.version.getVersionWrapper().isCropFullyGrown(event.getBlock()))
continue;
if ((!source.playerPlaced) && event.getBlock().hasMetadata("player_placed"))
continue;
if (source.matches(data, event.getBlock().getType()))
source.giveExperience(data);
}
}
};
}

View File

@ -83,9 +83,9 @@ public class BlockListener implements Listener {
PlayerData playerData = PlayerData.get(player);
info.getTriggers().forEach(trigger -> {
if(!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger)
trigger.apply(playerData);
trigger.apply(playerData);
});
if (info.hasExperience() && MMOCore.plugin.hasHolograms())
if(!block.hasMetadata("player_placed") && info.hasExperience() && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5, .5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + called.getGainedExperience().getValue()), player);
}

View File

@ -17,6 +17,8 @@ public abstract class ExperienceManager<T> implements Listener {
public void register(T source) {
sources.add(source);
getSources();
}
public Set<T> getSources() {

View File

@ -34,7 +34,7 @@ public class ProfessionManager extends MMOManager {
@SuppressWarnings("unchecked")
public <T extends ExperienceSource<?>> void registerExpSource(T source) {
Class<T> path = (Class<T>) source.getClass();
if (!managers.containsKey(path))
managers.put(path, source.newManager());
getManager(path).register(source);

View File

@ -9,6 +9,6 @@ experience:
per-level: 2
exp-sources:
- 'mineblock{type=CARROTS;amount=1-3;crop=true}'
- 'mineblock{type=POTATOES;amount=1-3;crop=true}'
- 'mineblock{type=WHEAT;amount=1-3;crop=true}'
- 'mineblock{type=CARROTS;amount=1-3;crop=true;player-placed:true}'
- 'mineblock{type=POTATOES;amount=1-3;crop=true;player-placed:true}'
- 'mineblock{type=WHEAT;amount=1-3;crop=true;player-placed:true}'