slight improvement with new exp api

This commit is contained in:
Indyuce 2021-12-27 12:52:09 +01:00
parent cd265e1d8f
commit 733f3c5239
6 changed files with 66 additions and 15 deletions

View File

@ -12,7 +12,8 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
public class ExperienceTrigger extends Trigger { public class ExperienceTrigger extends Trigger {
private final RandomAmount amount; private final RandomAmount amount;
private Profession profession; private final Profession profession;
private final EXPSource source;
public ExperienceTrigger(MMOLineConfig config) { public ExperienceTrigger(MMOLineConfig config) {
super(config); super(config);
@ -23,16 +24,18 @@ public class ExperienceTrigger extends Trigger {
String id = config.getString("profession").toLowerCase().replace("_", "-"); String id = config.getString("profession").toLowerCase().replace("_", "-");
Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession"); Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession");
profession = MMOCore.plugin.professionManager.get(id); profession = MMOCore.plugin.professionManager.get(id);
} } else
profession = null;
amount = new RandomAmount(config.getString("amount")); amount = new RandomAmount(config.getString("amount"));
source = config.contains("source") ? EXPSource.valueOf(config.getString("source").toUpperCase()) : EXPSource.QUEST;
} }
@Override @Override
public void apply(PlayerData player) { public void apply(PlayerData player) {
if (profession == null) if (profession == null)
player.giveExperience(amount.calculateInt(), EXPSource.QUEST); player.giveExperience(amount.calculateInt(), source);
else else
player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), EXPSource.QUEST); player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), source);
} }
/* /*

View File

@ -1,10 +1,36 @@
package net.Indyuce.mmocore.experience; package net.Indyuce.mmocore.experience;
public enum EXPSource { public enum EXPSource {
SOURCE,
COMMAND, /**
VANILLA, * When using a profession/class experience source
QUEST, */
FISHING, SOURCE,
OTHER
/**
* When using the /mmocore admin exp command
*/
COMMAND,
/**
* When converting vanilla exp into MMOCore exp
*/
VANILLA,
/**
* When using the experience trigger. Keep in mind the
* experience trigger can also use another experience source
* when using the right parameter
*/
QUEST,
/**
* When gaining experience from fishing
*/
FISHING,
/**
* Anything else
*/
OTHER
} }

View File

@ -73,7 +73,7 @@ public class Profession {
} }
} }
MMOCore.plugin.professionManager.loadProfessionConfigurations(config); MMOCore.plugin.professionManager.loadProfessionConfigurations(this, config);
} }
private ExperienceTable loadExperienceTable(Object obj) { private ExperienceTable loadExperienceTable(Object obj) {

View File

@ -188,9 +188,8 @@ public class FishingListener implements Listener {
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2, location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2,
4 * (random.nextDouble() - .5), .05); 4 * (random.nextDouble() - .5), .05);
if (MMOCore.plugin.professionManager.has("fishing")) if (MMOCore.plugin.fishingManager.hasLinkedProfession())
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, EXPSource.FISHING, playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), exp, EXPSource.FISHING, location);
location);
} }
} }
} }

View File

@ -31,10 +31,15 @@ public class ProfessionManager implements MMOCoreManager {
professionManagers.add(professionManager); professionManagers.add(professionManager);
} }
public void loadProfessionConfigurations(ConfigurationSection config) { /**
* @param profession Profession loading some configuration section
* @param config Configuration section to load profession config from
*/
public void loadProfessionConfigurations(Profession profession, ConfigurationSection config) {
for (SpecificProfessionManager manager : professionManagers) for (SpecificProfessionManager manager : professionManagers)
if (config.contains(manager.getStringKey())) if (config.contains(manager.getStringKey()))
try { try {
manager.setLinkedProfession(profession);
manager.loadProfessionConfiguration(config.getConfigurationSection(manager.getStringKey())); manager.loadProfessionConfiguration(config.getConfigurationSection(manager.getStringKey()));
} catch (RuntimeException exception) { } catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession config '" + manager.getStringKey() + "': " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession config '" + manager.getStringKey() + "': " + exception.getMessage());

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.manager.profession; package net.Indyuce.mmocore.manager.profession;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.manager.MMOCoreManager; import net.Indyuce.mmocore.manager.MMOCoreManager;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -11,10 +12,27 @@ public abstract class SpecificProfessionManager implements MMOCoreManager {
*/ */
private final String key; private final String key;
/**
* Caching the profession that is linked to the profession manager.
*/
private Profession linkedProfession;
public SpecificProfessionManager(String key) { public SpecificProfessionManager(String key) {
this.key = key; this.key = key;
} }
public void setLinkedProfession(Profession linkedProfession) {
this.linkedProfession = linkedProfession;
}
public Profession getLinkedProfession() {
return linkedProfession;
}
public boolean hasLinkedProfession() {
return linkedProfession != null;
}
public String getStringKey() { public String getStringKey() {
return key; return key;
} }