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)) { if (source.matches(player, null)) {
Map<Enchantment, Integer> ench = new HashMap<>(event.getEnchantsToAdd()); Map<Enchantment, Integer> ench = new HashMap<>(event.getEnchantsToAdd());
if (!enchants.isEmpty()) if (!source.enchants.isEmpty())
for (Iterator<Enchantment> iterator = ench.keySet().iterator(); iterator.hasNext();) for (Iterator<Enchantment> iterator = ench.keySet().iterator(); iterator.hasNext();)
if (!enchants.contains(iterator.next())) if (!source.enchants.contains(iterator.next()))
iterator.remove(); iterator.remove();
if (ench.isEmpty()) if (ench.isEmpty())

View File

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

View File

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

View File

@ -83,9 +83,9 @@ public class BlockListener implements Listener {
PlayerData playerData = PlayerData.get(player); PlayerData playerData = PlayerData.get(player);
info.getTriggers().forEach(trigger -> { info.getTriggers().forEach(trigger -> {
if(!block.hasMetadata("player_placed") && trigger instanceof ExperienceTrigger) 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); 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) { public void register(T source) {
sources.add(source); sources.add(source);
getSources();
} }
public Set<T> getSources() { public Set<T> getSources() {

View File

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

View File

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