From c6a45d512014066cf5b19ea854a09e6909d0845e Mon Sep 17 00:00:00 2001 From: Indyuce Date: Mon, 23 May 2022 12:45:53 +0200 Subject: [PATCH] Deprecated exp dispensers --- pom.xml | 2 +- .../api/player/profess/PlayerClass.java | 21 ++++++++++---- .../api/quest/trigger/ExperienceTrigger.java | 7 ++--- .../mmocore/experience/ExperienceObject.java | 9 ++++-- .../mmocore/experience/Profession.java | 23 +++++++++++---- ...enser.java => SimpleExperienceObject.java} | 6 ++-- .../dispenser/ClassExperienceDispenser.java | 28 ------------------- .../dispenser/ExperienceDispenser.java | 5 ++-- .../ProfessionExperienceDispenser.java | 27 ------------------ 9 files changed, 49 insertions(+), 79 deletions(-) rename src/main/java/net/Indyuce/mmocore/experience/{dispenser/SimpleExperienceDispenser.java => SimpleExperienceObject.java} (79%) delete mode 100644 src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java delete mode 100644 src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java diff --git a/pom.xml b/pom.xml index 85ecfca0..4f0e60df 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.Indyuce MMOCore - 1.9.2 + 1.9.3 MMOCore Offer your players a brand new RPG experience!! diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 346a2b9a..cbd9dcc4 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -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) { diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java index 4a84e0b0..a7181940 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java @@ -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; } diff --git a/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java b/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java index 3f9e6cc8..445e81c8 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java +++ b/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java @@ -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. + *

+ * 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(); diff --git a/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/experience/Profession.java index ade8f4fb..42db02b1 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -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,16 +64,14 @@ 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 @@ -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 { /** diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/SimpleExperienceObject.java similarity index 79% rename from src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java rename to src/main/java/net/Indyuce/mmocore/experience/SimpleExperienceObject.java index fc99e73b..87e013c7 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/SimpleExperienceObject.java @@ -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) { diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java deleted file mode 100644 index 917f7b14..00000000 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java index 5ac9eac0..ad2ce255 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java @@ -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. diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java deleted file mode 100644 index 273a05b2..00000000 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java +++ /dev/null @@ -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; - } -}