mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-03-01 15:51:06 +01:00
slight improvement with new exp api
This commit is contained in:
parent
cd265e1d8f
commit
733f3c5239
@ -12,7 +12,8 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
|
||||
public class ExperienceTrigger extends Trigger {
|
||||
private final RandomAmount amount;
|
||||
private Profession profession;
|
||||
private final Profession profession;
|
||||
private final EXPSource source;
|
||||
|
||||
public ExperienceTrigger(MMOLineConfig config) {
|
||||
super(config);
|
||||
@ -23,16 +24,18 @@ public class ExperienceTrigger extends Trigger {
|
||||
String id = config.getString("profession").toLowerCase().replace("_", "-");
|
||||
Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession");
|
||||
profession = MMOCore.plugin.professionManager.get(id);
|
||||
}
|
||||
} else
|
||||
profession = null;
|
||||
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(), EXPSource.QUEST);
|
||||
player.giveExperience(amount.calculateInt(), source);
|
||||
else
|
||||
player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), EXPSource.QUEST);
|
||||
player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), source);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,10 +1,36 @@
|
||||
package net.Indyuce.mmocore.experience;
|
||||
|
||||
public enum EXPSource {
|
||||
|
||||
/**
|
||||
* When using a profession/class experience source
|
||||
*/
|
||||
SOURCE,
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class Profession {
|
||||
}
|
||||
}
|
||||
|
||||
MMOCore.plugin.professionManager.loadProfessionConfigurations(config);
|
||||
MMOCore.plugin.professionManager.loadProfessionConfigurations(this, config);
|
||||
}
|
||||
|
||||
private ExperienceTable loadExperienceTable(Object obj) {
|
||||
|
@ -188,9 +188,8 @@ public class FishingListener implements Listener {
|
||||
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2,
|
||||
4 * (random.nextDouble() - .5), .05);
|
||||
|
||||
if (MMOCore.plugin.professionManager.has("fishing"))
|
||||
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, EXPSource.FISHING,
|
||||
location);
|
||||
if (MMOCore.plugin.fishingManager.hasLinkedProfession())
|
||||
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), exp, EXPSource.FISHING, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,15 @@ public class ProfessionManager implements MMOCoreManager {
|
||||
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)
|
||||
if (config.contains(manager.getStringKey()))
|
||||
try {
|
||||
manager.setLinkedProfession(profession);
|
||||
manager.loadProfessionConfiguration(config.getConfigurationSection(manager.getStringKey()));
|
||||
} catch (RuntimeException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession config '" + manager.getStringKey() + "': " + exception.getMessage());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.manager.profession;
|
||||
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
@ -11,10 +12,27 @@ public abstract class SpecificProfessionManager implements MMOCoreManager {
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* Caching the profession that is linked to the profession manager.
|
||||
*/
|
||||
private Profession linkedProfession;
|
||||
|
||||
public SpecificProfessionManager(String 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() {
|
||||
return key;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user