EXP dispensers cleanup

This commit is contained in:
Indyuce 2022-03-12 13:57:12 +01:00
parent d4813f5cfa
commit d1a241a60f
22 changed files with 78 additions and 72 deletions

View File

@ -1,6 +1,6 @@
package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.block.BlockType;

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;

View File

@ -18,8 +18,8 @@ import net.Indyuce.mmocore.loot.chest.particle.CastingParticle;
import net.Indyuce.mmocore.experience.ExpCurve;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.provider.MainExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ClassExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.player.playerclass.ClassTrigger;
import net.Indyuce.mmocore.player.playerclass.ClassTriggerType;
@ -155,7 +155,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
}
if (config.contains("main-exp-sources")) {
ExperienceDispenser dispenser = new MainExperienceDispenser(this);
ExperienceDispenser dispenser = new ClassExperienceDispenser(this);
for (String key : config.getStringList("main-exp-sources"))
try {
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser);

View File

@ -1,19 +1,24 @@
package net.Indyuce.mmocore.api.quest.trigger;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.SimpleExperienceDispenser;
import org.apache.commons.lang.Validate;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.ExperienceInfo;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import io.lumine.mythic.lib.api.MMOLineConfig;
import org.jetbrains.annotations.NotNull;
public class ExperienceTrigger extends Trigger {
@NotNull
private final RandomAmount amount;
private final Profession profession;
@NotNull
private final EXPSource source;
@NotNull
private final ExperienceDispenser dispenser;
public ExperienceTrigger(MMOLineConfig config) {
super(config);
@ -23,26 +28,15 @@ public class ExperienceTrigger extends Trigger {
if (config.contains("profession")) {
String id = config.getString("profession").toLowerCase().replace("_", "-");
Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession");
profession = MMOCore.plugin.professionManager.get(id);
dispenser = new ProfessionExperienceDispenser(MMOCore.plugin.professionManager.get(id));
} else
profession = null;
dispenser = new SimpleExperienceDispenser();
amount = new RandomAmount(config.getString("amount"));
source = config.contains("source") ? EXPSource.valueOf(config.getString("source").toUpperCase()) : EXPSource.QUEST;
}
@Override
public void apply(PlayerData player) {
if (profession == null)
player.giveExperience(amount.calculateInt(), source);
else
player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), source);
}
/*
* experience must be accessible from the custom mine event. this method
* allows to generate an experience info instance for easy manipulations
*/
public ExperienceInfo newInfo() {
return new ExperienceInfo(amount.calculateInt(), profession);
dispenser.giveExperience(player, amount.calculateInt(), null, source);
}
}

View File

@ -1,19 +0,0 @@
package net.Indyuce.mmocore.experience;
public class ExperienceInfo {
private final Profession profess;
private final int value;
public ExperienceInfo(int value, Profession profess) {
this.value = value;
this.profess = profess;
}
public Profession getProfession() {
return profess;
}
public int getValue() {
return value;
}
}

View File

@ -5,8 +5,8 @@ import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.provider.ProfessionExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.experience.provider;
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -7,18 +7,18 @@ import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class MainExperienceDispenser implements ExperienceDispenser {
public class ClassExperienceDispenser implements ExperienceDispenser {
private final PlayerClass profess;
public MainExperienceDispenser(PlayerClass profess) {
public ClassExperienceDispenser(PlayerClass profess) {
this.profess = profess;
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation) {
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation;
playerData.giveExperience(experience, EXPSource.SOURCE, hologramLocation, true);
playerData.giveExperience(experience, source, hologramLocation, true);
}
@Override

View File

@ -1,12 +1,15 @@
package net.Indyuce.mmocore.experience.provider;
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Used to differenciate between the main class experience
* and experience given in a specific profession
* Used to differenciate between the main class experience and
* experience given in a specific profession. Also being used to
* monitor EXP holograms.
*/
public interface ExperienceDispenser {
@ -17,10 +20,12 @@ public interface ExperienceDispenser {
* @param experience Experience gained. Note that it is a double
* because it gets converted to an integer at
* the very last moment in MMOCore
* @param hologramLocation Location of displayed hologram, nothing
* is displayed if it's null
* @param hologramLocation Location of displayed hologram. When set to null
* and if exp holograms are enabled it will take the
* player's location instead.
* @param source Why the EXP was gained
*/
void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation);
void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, @NotNull EXPSource source);
/**
* Experience sources handle both CLASS experience sources and PROFESSION

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.experience.provider;
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.Profession;
@ -14,7 +14,7 @@ public class ProfessionExperienceDispenser implements ExperienceDispenser {
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation) {
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation;
playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation);

View File

@ -0,0 +1,22 @@
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class SimpleExperienceDispenser implements ExperienceDispenser {
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation;
playerData.giveExperience(experience, source, hologramLocation, true);
}
@Override
public boolean shouldHandle(PlayerData playerData) {
return true;
}
}

View File

@ -2,7 +2,8 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
@ -167,7 +168,7 @@ public class BrewPotionExperienceSource extends ExperienceSource<PotionMeta> {
*/
// exp += getTotal(mapEffectDurations());
getDispenser().giveExperience(PlayerData.get(player), (int) exp * multiplier, null);
getDispenser().giveExperience(PlayerData.get(player), (int) exp * multiplier, null, EXPSource.SOURCE);
}
}
}

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate;

View File

@ -4,7 +4,8 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.enchantments.Enchantment;
@ -59,7 +60,7 @@ public class EnchantItemExperienceSource extends ExperienceSource<Void> {
double exp = 0;
for (Entry<Enchantment, Integer> entry : applicableEnchants.entrySet())
exp += MMOCore.plugin.enchantManager.getBaseExperience(entry.getKey()) * entry.getValue();
getDispenser().giveExperience(player, (int) exp, event.getEnchantBlock().getLocation());
getDispenser().giveExperience(player, (int) exp, event.getEnchantBlock().getLocation(), EXPSource.SOURCE);
}
}
};

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Bukkit;

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.GameMode;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;

View File

@ -2,7 +2,8 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
@ -74,7 +75,7 @@ public class RepairItemExperienceSource extends ExperienceSource<ItemStack> {
*/
double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType())
* Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100;
getDispenser().giveExperience(data, (int) exp, null);
getDispenser().giveExperience(data, (int) exp, null, EXPSource.SOURCE);
}
}
}

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Location;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.experience.source.type;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
public abstract class ExperienceSource<T> {

View File

@ -1,7 +1,8 @@
package net.Indyuce.mmocore.experience.source.type;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import org.bukkit.Location;
@ -41,6 +42,6 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
* @param hologramLocation Location used to display the exp hologram
*/
public void giveExperience(PlayerData player, double multiplier, @Nullable Location hologramLocation) {
getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation);
getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation, EXPSource.SOURCE);
}
}

View File

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;