From c98a952261421f6d9bc2916f753cbe70be23d081 Mon Sep 17 00:00:00 2001 From: Aria Date: Fri, 13 Sep 2019 01:35:30 +0200 Subject: [PATCH] Fixed exp sources --- .../source/EnchantItemExperienceSource.java | 4 ++-- .../source/KillMobExperienceSource.java | 3 ++- .../source/MineBlockExperienceSource.java | 24 +++++++++++-------- .../mmocore/listener/BlockListener.java | 4 ++-- .../manager/profession/ExperienceManager.java | 2 ++ .../manager/profession/ProfessionManager.java | 2 +- .../resources/default/professions/farming.yml | 6 ++--- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java index baa3295c..9fa606f1 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java @@ -49,9 +49,9 @@ public class EnchantItemExperienceSource extends ExperienceSource { if (source.matches(player, null)) { Map ench = new HashMap<>(event.getEnchantsToAdd()); - if (!enchants.isEmpty()) + if (!source.enchants.isEmpty()) for (Iterator iterator = ench.keySet().iterator(); iterator.hasNext();) - if (!enchants.contains(iterator.next())) + if (!source.enchants.contains(iterator.next())) iterator.remove(); if (ench.isEmpty()) diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java index a5031f7a..7e9c8475 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java @@ -13,7 +13,7 @@ import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.profession.ExperienceManager; public class KillMobExperienceSource extends SpecificExperienceSource { - 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 { 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); diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java index 69122dea..656a7869 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java @@ -16,9 +16,10 @@ import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.profession.ExperienceManager; public class MineBlockExperienceSource extends SpecificExperienceSource { - 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 { 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); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java index 3fc25a01..d90ca5c9 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java @@ -17,6 +17,8 @@ public abstract class ExperienceManager implements Listener { public void register(T source) { sources.add(source); + + getSources(); } public Set getSources() { diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java index a4395a5f..08c810ff 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java @@ -34,7 +34,7 @@ public class ProfessionManager extends MMOManager { @SuppressWarnings("unchecked") public > void registerExpSource(T source) { Class path = (Class) source.getClass(); - + if (!managers.containsKey(path)) managers.put(path, source.newManager()); getManager(path).register(source); diff --git a/src/main/resources/default/professions/farming.yml b/src/main/resources/default/professions/farming.yml index 747c3279..bb66ec5f 100644 --- a/src/main/resources/default/professions/farming.yml +++ b/src/main/resources/default/professions/farming.yml @@ -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}'