Deprecated exp dispensers

This commit is contained in:
Indyuce 2022-05-23 12:45:53 +02:00
parent 75a4b944b6
commit c6a45d5120
9 changed files with 49 additions and 79 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.9.2</version>
<version>1.9.3</version>
<name>MMOCore</name>
<description>Offer your players a brand new RPG experience!!</description>

View File

@ -8,6 +8,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.event.EventTrigger;
import net.Indyuce.mmocore.api.player.profess.resource.ManaDisplayOptions;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
@ -15,19 +16,18 @@ import net.Indyuce.mmocore.api.player.profess.resource.ResourceRegeneration;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.EXPSource;
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.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;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.configuration.ConfigurationSection;
@ -156,10 +156,9 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
}
if (config.contains("main-exp-sources")) {
ExperienceDispenser dispenser = new ClassExperienceDispenser(this);
for (String key : config.getStringList("main-exp-sources"))
try {
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser);
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this);
MMOCore.plugin.experience.registerSource(source);
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '"
@ -299,6 +298,18 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return options.containsKey(option) ? options.get(option) : option.getDefault();
}
@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;
playerData.giveExperience(experience, source, hologramLocation, true);
}
@Override
public boolean shouldHandle(PlayerData playerData) {
return equals(playerData.getProfess());
}
@Nullable
@Deprecated
public ClassTrigger getClassTrigger(ClassTriggerType type) {

View File

@ -1,8 +1,7 @@
package net.Indyuce.mmocore.api.quest.trigger;
import net.Indyuce.mmocore.experience.SimpleExperienceObject;
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;
@ -28,9 +27,9 @@ 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");
dispenser = new ProfessionExperienceDispenser(MMOCore.plugin.professionManager.get(id));
dispenser = MMOCore.plugin.professionManager.get(id);
} else
dispenser = new SimpleExperienceDispenser();
dispenser = new SimpleExperienceObject();
amount = new RandomAmount(config.getString("amount"));
source = config.contains("source") ? EXPSource.valueOf(config.getString("source").toUpperCase()) : EXPSource.QUEST;
}

View File

@ -1,16 +1,21 @@
package net.Indyuce.mmocore.experience;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
/**
* Either a profession or a class
* General implementation for professions and classes.
* <p>
* An experience object is a type of object that can
* level up. It has an experience curve and table and
* can receive EXP
*
* @author jules
*/
public interface ExperienceObject {
public interface ExperienceObject extends ExperienceDispenser {
String getKey();

View File

@ -3,14 +3,15 @@ package net.Indyuce.mmocore.experience;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
@ -63,17 +64,15 @@ public class Profession extends PostLoadObject implements ExperienceObject {
maxLevel = config.getInt("max-level");
if (config.contains("exp-sources")) {
ExperienceDispenser dispenser = new ProfessionExperienceDispenser(this);
if (config.contains("exp-sources"))
for (String key : config.getStringList("exp-sources"))
try {
MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser));
MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage());
}
}
}
@Override
protected void whenPostLoaded(ConfigurationSection configurationSection) {
@ -124,6 +123,18 @@ public class Profession extends PostLoadObject implements ExperienceObject {
return Objects.requireNonNull(expTable, "Profession has no exp table");
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null
: hologramLocation;
playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation);
}
@Override
public boolean shouldHandle(PlayerData playerData) {
return true;
}
public static enum ProfessionOption {
/**

View File

@ -1,12 +1,12 @@
package net.Indyuce.mmocore.experience.dispenser;
package net.Indyuce.mmocore.experience;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class SimpleExperienceDispenser implements ExperienceDispenser {
public class SimpleExperienceObject implements ExperienceDispenser {
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {

View File

@ -1,28 +0,0 @@
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class ClassExperienceDispenser implements ExperienceDispenser {
private final PlayerClass profess;
public ClassExperienceDispenser(PlayerClass profess) {
this.profess = profess;
}
@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;
playerData.giveExperience(experience, source, hologramLocation, true);
}
@Override
public boolean shouldHandle(PlayerData playerData) {
return playerData.getProfess().equals(profess);
}
}

View File

@ -12,15 +12,14 @@ import org.jetbrains.annotations.Nullable;
* experience given in a specific profession. Also being used to
* monitor EXP holograms.
*/
@Deprecated
public interface ExperienceDispenser {
/**
* Called when experience is gained in main class/profession
*
* @param playerData Player gaining the experience
* @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 experience Experience gained
* @param hologramLocation Location of displayed hologram. When set to null
* and if exp holograms are enabled it will take the
* player's location instead.

View File

@ -1,27 +0,0 @@
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class ProfessionExperienceDispenser implements ExperienceDispenser {
private final Profession profession;
public ProfessionExperienceDispenser(Profession profession) {
this.profession = profession;
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null
: hologramLocation;
playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation);
}
@Override
public boolean shouldHandle(PlayerData playerData) {
return true;
}
}