From d4071f532e787b13850051ad6223ff664e88b863 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 21 Aug 2021 00:36:26 +0200 Subject: [PATCH] !exp source refactor --- .../java/net/Indyuce/mmocore/MMOCore.java | 5 +- .../api/event/PlayerExperienceGainEvent.java | 4 +- .../mmocore/api/event/PlayerLevelUpEvent.java | 2 +- .../mmocore/api/experience/Profession.java | 188 ------- .../source/BrewPotionExperienceSource.java | 173 ------- .../source/CraftItemExperienceSource.java | 45 -- .../source/EnchantItemExperienceSource.java | 63 --- .../source/FishItemExperienceSource.java | 51 -- .../source/KillMobExperienceSource.java | 51 -- .../source/MineBlockExperienceSource.java | 67 --- .../source/PlaceBlockExperienceSource.java | 47 -- .../source/RepairItemExperienceSource.java | 84 --- .../source/SmeltItemExperienceSource.java | 70 --- .../source/type/ExperienceSource.java | 81 --- .../source/type/SpecificExperienceSource.java | 47 -- .../mmocore/api/load/DefaultMMOLoader.java | 42 +- .../Indyuce/mmocore/api/load/MMOLoader.java | 54 +- .../mmocore/api/player/PlayerData.java | 8 +- .../api/player/profess/PlayerClass.java | 486 +++++++++--------- .../mmocore/api/player/stats/StatType.java | 2 +- .../net/Indyuce/mmocore/api/quest/Quest.java | 2 +- .../api/quest/trigger/ExperienceTrigger.java | 6 +- .../rpg/admin/ExperienceCommandTreeNode.java | 6 +- .../rpg/admin/InfoCommandTreeNode.java | 2 +- .../rpg/admin/LevelCommandTreeNode.java | 6 +- .../rpg/admin/ResetCommandTreeNode.java | 2 +- .../rpg/booster/CreateCommandTreeNode.java | 4 +- .../rpg/booster/ListCommandTreeNode.java | 2 +- .../rpg/booster/RemoveCommandTreeNode.java | 2 +- .../comp/mythicmobs/MythicMobsMMOLoader.java | 11 +- .../KillMythicFactionExperienceSource.java | 69 ++- .../load/KillMythicMobExperienceSource.java | 67 ++- .../comp/placeholder/RPGPlaceholders.java | 4 +- .../mmocore/{api => }/experience/Booster.java | 2 +- .../{api => }/experience/EXPSource.java | 2 +- .../{api => }/experience/ExpCurve.java | 152 +++--- .../{api => }/experience/ExperienceInfo.java | 2 +- .../experience/PlayerProfessions.java | 8 +- .../mmocore/experience/Profession.java | 191 +++++++ .../provider/ExperienceDispenser.java | 30 ++ .../provider/MainExperienceDispenser.java | 29 ++ .../ProfessionExperienceDispenser.java | 27 + .../source/BrewPotionExperienceSource.java | 170 ++++++ .../source/CraftItemExperienceSource.java | 44 ++ .../source/EnchantItemExperienceSource.java | 62 +++ .../source/FishItemExperienceSource.java | 50 ++ .../source/KillMobExperienceSource.java | 50 ++ .../source/MineBlockExperienceSource.java | 66 +++ .../source/PlaceBlockExperienceSource.java | 45 ++ .../source/RepairItemExperienceSource.java | 83 +++ .../source/SmeltItemExperienceSource.java | 69 +++ .../source/type/ExperienceSource.java | 30 ++ .../source/type/SpecificExperienceSource.java | 46 ++ .../net/Indyuce/mmocore/gui/PlayerStats.java | 4 +- .../net/Indyuce/mmocore/gui/QuestViewer.java | 2 +- .../listener/option/RedirectVanillaExp.java | 2 +- .../listener/profession/FishingListener.java | 2 +- .../mmocore/manager/AttributeManager.java | 2 +- .../Indyuce/mmocore/manager/ClassManager.java | 2 +- .../mmocore/manager/CustomBlockManager.java | 2 +- .../mmocore/manager/DropTableManager.java | 2 +- .../mmocore/manager/ExperienceManager.java | 2 +- .../mmocore/manager/MMOLoadManager.java | 8 +- .../Indyuce/mmocore/manager/MMOManager.java | 6 +- .../Indyuce/mmocore/manager/QuestManager.java | 2 +- .../manager/profession/AlchemyManager.java | 2 +- .../manager/profession/EnchantManager.java | 2 +- .../manager/profession/ExperienceManager.java | 27 - .../profession/ExperienceSourceManager.java | 30 ++ .../manager/profession/FishingManager.java | 2 +- .../manager/profession/ProfessionManager.java | 22 +- .../manager/profession/SmithingManager.java | 2 +- .../manager/social/BoosterManager.java | 4 +- .../mmocore/manager/social/PartyManager.java | 2 +- 74 files changed, 1536 insertions(+), 1504 deletions(-) delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/Profession.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/PlaceBlockExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java rename src/main/java/net/Indyuce/mmocore/{api => }/experience/Booster.java (98%) rename src/main/java/net/Indyuce/mmocore/{api => }/experience/EXPSource.java (64%) rename src/main/java/net/Indyuce/mmocore/{api => }/experience/ExpCurve.java (95%) rename src/main/java/net/Indyuce/mmocore/{api => }/experience/ExperienceInfo.java (87%) rename src/main/java/net/Indyuce/mmocore/{api => }/experience/PlayerProfessions.java (95%) create mode 100644 src/main/java/net/Indyuce/mmocore/experience/Profession.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/BrewPotionExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/EnchantItemExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/FishItemExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/MineBlockExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/PlaceBlockExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/RepairItemExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/SmeltItemExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java create mode 100644 src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java delete mode 100644 src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java create mode 100644 src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index d9f29bdc..b3a9ec8c 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -95,8 +95,11 @@ public class MMOCore extends LuminePlugin { public boolean shouldDebugSQL = false; - public void load() { + public MMOCore() { plugin = this; + } + + public void load() { /* * register extra objective, drop items... diff --git a/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java index bdc6a9a1..72ed5928 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java @@ -5,8 +5,8 @@ import javax.annotation.Nullable; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.EXPSource; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancellable { diff --git a/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java index 35e9c4a2..b02a90bc 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java @@ -2,7 +2,7 @@ package net.Indyuce.mmocore.api.event; import org.bukkit.event.HandlerList; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; public class PlayerLevelUpEvent extends PlayerDataEvent { diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java deleted file mode 100644 index cff76488..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java +++ /dev/null @@ -1,188 +0,0 @@ -package net.Indyuce.mmocore.api.experience; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.logging.Level; - -import org.apache.commons.lang.Validate; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.potion.PotionType; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.util.math.formula.LinearValue; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.MMOLineConfig; -import io.lumine.mythic.lib.api.util.PostLoadObject; - -public class Profession extends PostLoadObject { - private final String id, name; - private final ExpCurve expCurve; - private final int maxLevel; - private final Map options = new HashMap<>(); - - /* - * experience given to the main player level whenever he levels up this - * profession - */ - private final LinearValue experience; - - public Profession(String id, FileConfiguration config) { - super(config); - - this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); - this.name = config.getString("name"); - Validate.notNull(name, "Could not load name"); - - expCurve = config.contains("exp-curve") - ? MMOCore.plugin.experience.getOrThrow(config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) - : ExpCurve.DEFAULT; - experience = new LinearValue(config.getConfigurationSection("experience")); - - if (config.contains("options")) - for (String key : config.getConfigurationSection("options").getKeys(false)) - try { - ProfessionOption option = ProfessionOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); - options.put(option, config.getBoolean("options." + key)); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, - "Could not load option '" + key + "' from profession '" + id + "': " + exception.getMessage()); - } - - maxLevel = config.getInt("max-level"); - - if (config.contains("exp-sources")) - for (String key : config.getStringList("exp-sources")) - try { - MMOCore.plugin.professionManager.registerExpSource(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()); - } - } - - /* - * drop tables must be loaded after professions are initialized - */ - @Override - protected void whenPostLoaded(ConfigurationSection config) { - - if (config.contains("on-fish")) - MMOCore.plugin.fishingManager.loadDropTables(config.getConfigurationSection("on-fish")); - - if (config.contains("on-mine")) - MMOCore.plugin.mineManager.loadDropTables(config.getConfigurationSection("on-mine")); - - if (config.contains("alchemy-experience")) { - - MMOCore.plugin.alchemyManager.splash = 1 + config.getDouble("alchemy-experience.special.splash") / 100; - MMOCore.plugin.alchemyManager.lingering = 1 + config.getDouble("alchemy-experience.special.lingering") / 100; - MMOCore.plugin.alchemyManager.extend = 1 + config.getDouble("alchemy-experience.special.extend") / 100; - MMOCore.plugin.alchemyManager.upgrade = 1 + config.getDouble("alchemy-experience.special.upgrade") / 100; - - for (String key : config.getConfigurationSection("alchemy-experience.effects").getKeys(false)) - try { - PotionType type = PotionType.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); - MMOCore.plugin.alchemyManager.registerBaseExperience(type, config.getDouble("alchemy-experience.effects." + key)); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read potion type from " + key); - } - } - - if (config.contains("base-enchant-exp")) - for (String key : config.getConfigurationSection("base-enchant-exp").getKeys(false)) - try { - Enchantment enchant = MythicLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_")); - MMOCore.plugin.enchantManager.registerBaseExperience(enchant, config.getDouble("base-enchant-exp." + key)); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read enchant from " + key); - } - - if (config.contains("repair-exp")) - for (String key : config.getConfigurationSection("repair-exp").getKeys(false)) - try { - Material material = Material.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); - MMOCore.plugin.smithingManager.registerBaseExperience(material, config.getDouble("repair-exp." + key)); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read material from " + key); - } - - // if (config.contains("effect-weight")) - // for (String key : - // config.getConfigurationSection("effect-weight").getKeys(false)) - // try { - // MMOCore.plugin.alchemyManager.registerEffectWeight(PotionEffectType.getByName(key.toUpperCase().replace("-", - // "_").replace(" ", "_")), config.getDouble("effect-weight." + key)); - // } catch (IllegalArgumentException exception) { - // MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not - // read - // potion effect type from " + key); - // } - } - - public boolean getOption(ProfessionOption option) { - return options.getOrDefault(option, option.getDefault()); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public ExpCurve getExpCurve() { - return expCurve; - } - - public int getMaxLevel() { - return maxLevel; - } - - public boolean hasMaxLevel() { - return maxLevel > 0; - } - - public int calculateExperience(int x) { - return (int) experience.calculate(x); - } - - public LinearValue getExperience() { - return experience; - } - - public static enum ProfessionOption { - - /** - * When disabled, removes exp holograms when mined - */ - EXP_HOLOGRAMS(true); - - private final boolean def; - - private ProfessionOption(boolean def) { - this.def = def; - } - - public boolean getDefault() { - return def; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Profession that = (Profession) o; - return id.equals(that.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java deleted file mode 100644 index 1e7cbf42..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/BrewPotionExperienceSource.java +++ /dev/null @@ -1,173 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.BrewEvent; -import org.bukkit.inventory.BrewerInventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionType; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - -public class BrewPotionExperienceSource extends ExperienceSource { - private final List types = new ArrayList<>(); - - public BrewPotionExperienceSource(Profession profession, MMOLineConfig config) { - super(profession); - - if (config.contains("effect")) - for (String key : config.getString("effect").split(",")) - types.add(PotionType.valueOf(key.toUpperCase().replace("-", "_"))); - } - - @Override - public boolean matches(PlayerData player, PotionMeta meta) { - return hasRightClass(player) - && (types.isEmpty() || new ArrayList<>(types).stream().anyMatch(type -> meta.getBasePotionData().getType() == type)); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(BrewEvent event) { - Optional playerOpt = getNearbyPlayer(event.getBlock().getLocation()); - if (!playerOpt.isPresent()) - return; - - final ItemStack found = findPotion(event.getContents()); - if (found != null) - Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, () -> { - ItemStack brewn = findPotion(event.getContents()); - if (brewn == null) - return; - - PlayerData data = PlayerData.get(playerOpt.get()); - if(!data.isOnline()) return; - for (BrewPotionExperienceSource source : getSources()) - if (source.matches(data, (PotionMeta) brewn.getItemMeta())) - new PotionUpgrade(found, brewn).process(data.getPlayer()); - }); - } - }; - } - - private ItemStack findPotion(BrewerInventory inv) { - for (int j = 0; j < 3; j++) { - ItemStack item = inv.getItem(j); - if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) - return item; - } - return null; - } - - private Optional getNearbyPlayer(Location loc) { - return loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < 100).findAny(); - } - - public class PotionUpgrade { - - /* - * if the potion was extended using redstone or upgraded using - * glowstone. PREPARE corresponds to when a water bottle is prepared for - * later recipes using NETHER STALK - */ - private double exp; - - // private final PotionMeta old, brewn; - - public PotionUpgrade(ItemStack old, ItemStack brewn) { - this(old.getType(), (PotionMeta) old.getItemMeta(), brewn.getType(), (PotionMeta) brewn.getItemMeta()); - } - - public PotionUpgrade(Material oldPot, PotionMeta old, Material brewnPot, PotionMeta brewn) { - - // this.old = old; - // this.brewn = brewn; - - /* - * calculate base exp - */ - - exp += MMOCore.plugin.alchemyManager.getBaseExperience(brewn.getBasePotionData().getType()); - - // !old.getBasePotionData().getType().isUpgradeable() && - // brewn.getBasePotionData().getType().isUpgradeable(), - // - // !old.getBasePotionData().isExtended() && - // brewn.getBasePotionData().isExtended(), - // - // !old.getBasePotionData().isUpgraded() && - // brewn.getBasePotionData().isUpgraded()); - - /* - * EXP modifiers based on brewing conditions - */ - if (oldPot == Material.POTION && brewnPot == Material.SPLASH_POTION) - exp *= MMOCore.plugin.alchemyManager.splash; - if (oldPot == Material.POTION && brewnPot == Material.LINGERING_POTION) - exp *= MMOCore.plugin.alchemyManager.lingering; - if (!old.getBasePotionData().isExtended() && brewn.getBasePotionData().isExtended()) - exp *= MMOCore.plugin.alchemyManager.extend; - if (!old.getBasePotionData().isUpgraded() && brewn.getBasePotionData().isUpgraded()) - exp *= MMOCore.plugin.alchemyManager.upgrade; - } - - // private Map mapEffectDurations() { - // Map map = new HashMap<>(); - // - // /* - // * potion level, plus the potion gained duration (max 0 so it does - // * not give negative EXP), multiplied by the potion effect weight. - // */ - // brewn.getCustomEffects().forEach(effect -> map.put(effect.getType(), - // - // (effect.getAmplifier() + 1 + (double) Math.max(0, - // effect.getDuration() - getPotionEffect(old, - // effect.getType()).orElseGet(() -> new - // PotionEffect(PotionEffectType.SPEED, 0, 0)).getDuration()) / 60.) - // - // * MMOCore.plugin.alchemyManager.getWeight(effect.getType()))); - // - // return map; - // } - - // private int getTotal(Map map) { - // double t = 0; - // for (double d : map.values()) - // t += d; - // return (int) t; - // } - - // private Optional getPotionEffect(PotionMeta meta, - // PotionEffectType type) { - // return meta.getCustomEffects().stream().filter(effect -> - // effect.getType() == type).findFirst(); - // } - - public void process(Player player) { - - /* - * calculate extra exp due to extra effects - */ - // exp += getTotal(mapEffectDurations()); - - giveExperience(PlayerData.get(player), (int) exp, null); - } - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java deleted file mode 100644 index 1d8f6bca..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/CraftItemExperienceSource.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.CraftItemEvent; - -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; -import org.bukkit.event.inventory.InventoryAction; - -public class CraftItemExperienceSource extends SpecificExperienceSource { - public final Material material; - - public CraftItemExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); - - config.validate("type"); - material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(CraftItemEvent event) { - if(event.getAction() == InventoryAction.NOTHING || - event.getInventory().getResult() == null) return; - PlayerData data = PlayerData.get((Player) event.getWhoClicked()); - for (CraftItemExperienceSource source : getSources()) - if (source.matches(data, event.getInventory().getResult().getType())) - source.giveExperience(data, event.getInventory().getResult().getAmount(), event.getInventory().getLocation()); - } - }; - } - - @Override - public boolean matches(PlayerData player, Material obj) { - return material == obj && hasRightClass(player); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java deleted file mode 100644 index f6ad18ed..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/EnchantItemExperienceSource.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.enchantment.EnchantItemEvent; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; -import io.lumine.mythic.lib.MythicLib; - -public class EnchantItemExperienceSource extends ExperienceSource { - private final List enchants = new ArrayList<>(); - - public EnchantItemExperienceSource(Profession profession, MMOLineConfig config) { - super(profession); - - if (config.contains("enchant")) - for (String key : config.getString("enchant").split(",")) - enchants.add(MythicLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_"))); - } - - @Override - public boolean matches(PlayerData player, Void v) { - return hasRightClass(player); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(EnchantItemEvent event) { - PlayerData player = PlayerData.get(event.getEnchanter()); - for (EnchantItemExperienceSource source : getSources()) - if (source.matches(player, null)) { - Map ench = new HashMap<>(event.getEnchantsToAdd()); - - if (!source.enchants.isEmpty()) - ench.keySet().removeIf(enchantment -> !source.enchants.contains(enchantment)); - - if (ench.isEmpty()) - continue; - - double exp = 0; - for (Entry entry : ench.entrySet()) - exp += MMOCore.plugin.enchantManager.getBaseExperience(entry.getKey()) * entry.getValue(); - giveExperience(player, (int) exp, event.getEnchantBlock().getLocation()); - } - } - }; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java deleted file mode 100644 index f5f34962..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/FishItemExperienceSource.java +++ /dev/null @@ -1,51 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import org.bukkit.Material; -import org.bukkit.entity.Item; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerFishEvent.State; -import org.bukkit.inventory.ItemStack; - -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - -public class FishItemExperienceSource extends SpecificExperienceSource { - private final Material material; - - public FishItemExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); - - config.validate("type"); - material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(PlayerFishEvent event) { - if (event.getState() == State.CAUGHT_FISH) { - ItemStack caught = ((Item) event.getCaught()).getItemStack(); - if (caught.hasItemMeta()) - return; - - PlayerData data = PlayerData.get(event.getPlayer()); - for (FishItemExperienceSource source : getSources()) - if (source.matches(data, caught)) - source.giveExperience(data, caught.getAmount(), event.getHook().getLocation().add(0, 1.0f, 0)); - } - } - }; - } - - @Override - public boolean matches(PlayerData player, ItemStack obj) { - return hasRightClass(player) && obj.getType() == material; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java deleted file mode 100644 index 0635a2f0..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/KillMobExperienceSource.java +++ /dev/null @@ -1,51 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; -import io.lumine.mythic.lib.api.event.EntityKillEntityEvent; - -public class KillMobExperienceSource extends SpecificExperienceSource { - public final EntityType type; - - public KillMobExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); - - config.validate("type"); - type = EntityType.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(EntityKillEntityEvent event) { - Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { - if (event.getTarget().isDead() && event.getEntity() instanceof Player && !event.getEntity().hasMetadata("NPC") - && !event.getTarget().hasMetadata("spawner_spawned")) { - PlayerData data = PlayerData.get((Player) event.getEntity()); - - for (KillMobExperienceSource source : getSources()) - if (source.matches(data, event.getTarget())) - source.giveExperience(data, 1, event.getTarget().getLocation()); - } - }, 2); - } - }; - } - - @Override - public boolean matches(PlayerData player, Entity obj) { - return hasRightClass(player) && obj.getType() == type; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java deleted file mode 100644 index ab17a2b2..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/MineBlockExperienceSource.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.inventory.ItemStack; - -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.MMOLineConfig; - -public class MineBlockExperienceSource extends SpecificExperienceSource { - public final Material material; - private final boolean silkTouch; - private final boolean crop; - private final boolean playerPlaced; - - public MineBlockExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); - - config.validate("type"); - material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); - silkTouch = config.getBoolean("silk-touch", true); - crop = config.getBoolean("crop", false); - playerPlaced = config.getBoolean("player-placed", false); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(BlockBreakEvent event) { - if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) - return; - - PlayerData data = PlayerData.get(event.getPlayer()); - - for (MineBlockExperienceSource source : getSources()) { - if (source.silkTouch && hasSilkTouch(event.getPlayer().getInventory().getItemInMainHand())) - continue; - if (source.crop && !MythicLib.plugin.getVersion().getWrapper().isCropFullyGrown(event.getBlock())) - continue; - if ((!source.playerPlaced) && event.getBlock().hasMetadata("player_placed")) - continue; - - if (source.matches(data, event.getBlock().getType())) - source.giveExperience(data, 1, event.getBlock().getLocation()); - } - } - }; - } - - private boolean hasSilkTouch(ItemStack item) { - return item != null && item.hasItemMeta() && item.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH); - } - - @Override - public boolean matches(PlayerData player, Material obj) { - return material == obj && hasRightClass(player); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/PlaceBlockExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/PlaceBlockExperienceSource.java deleted file mode 100644 index 2e45f392..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/PlaceBlockExperienceSource.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPlaceEvent; - -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - -public class PlaceBlockExperienceSource extends SpecificExperienceSource { - public final Material material; - - public PlaceBlockExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); - - config.validate("type"); - material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void a(BlockPlaceEvent event) { - if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) - return; - - PlayerData data = PlayerData.get(event.getPlayer()); - - for (PlaceBlockExperienceSource source : getSources()) - if (source.matches(data, event.getBlock().getType())) - source.giveExperience(data, 1, event.getBlock().getLocation()); - } - }; - } - - @Override - public boolean matches(PlayerData player, Material obj) { - return material == obj && hasRightClass(player); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java deleted file mode 100644 index 810fff3c..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/RepairItemExperienceSource.java +++ /dev/null @@ -1,84 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.AnvilInventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - -public class RepairItemExperienceSource extends ExperienceSource { - private final Material material; - - public RepairItemExperienceSource(Profession profession, MMOLineConfig config) { - super(profession); - - /* - * if material is null, the player can repair ANY material in order to - * get experience. - */ - material = config.contains("type") ? Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")) : null; - } - - @Override - public boolean matches(PlayerData player, ItemStack item) { - return (material == null || item.getType() == material) && hasRightClass(player); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(InventoryClickEvent event) { - if (event.getInventory() != null && event.getInventory().getType() == InventoryType.ANVIL && event.getSlot() == 2) { - - ItemStack item = event.getCurrentItem(); - PlayerData data = PlayerData.get((Player) event.getWhoClicked()); - - for (RepairItemExperienceSource source : getSources()) - if (source.matches(data, item)) { - - if (!(event.getInventory() instanceof AnvilInventory)) - return; - - if (((AnvilInventory) event.getInventory()).getRepairCost() > ((Player) event.getWhoClicked()).getLevel()) - return; - - /* - * make sure the items can actually be repaired - * before getting the amount of durability repaired - */ - ItemStack old = event.getInventory().getItem(0); - if (old == null || old.getType() == Material.AIR) - return; - if (old.getType().getMaxDurability() < 30 || item.getType().getMaxDurability() < 10) - return; - - if (!MMOCore.plugin.smithingManager.hasExperience(item.getType())) - continue; - - /* - * calculate exp based on amount of durability which - * was repaired, substract damage from old item - * durability. - */ - double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType()) - * Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100; - giveExperience(data, (int) exp, null); - } - } - } - }; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java deleted file mode 100644 index 5e8391df..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/SmeltItemExperienceSource.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source; - -import java.util.Optional; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockCookEvent; -import org.bukkit.inventory.ItemStack; - -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - -public class SmeltItemExperienceSource extends SpecificExperienceSource { - private final Material material; - - public SmeltItemExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); - - config.validate("type"); - material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); - } - - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(BlockCookEvent event) { - Optional player = getNearestPlayer(event.getBlock().getLocation()); - if (!player.isPresent()) - return; - - ItemStack caught = event.getResult(); - if (caught.hasItemMeta()) - return; - - PlayerData data = PlayerData.get(player.get()); - for (SmeltItemExperienceSource source : getSources()) - if (source.matches(data, caught)) - source.giveExperience(data, 1, event.getBlock().getLocation()); - } - }; - } - - private Optional getNearestPlayer(Location loc) { - final Player[] nearby = loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < 100) - .toArray(Player[]::new); - Player selected = null; - double lastDist = 100; - for (Player p : nearby) { - double currDist = p.getLocation().distance(loc); - if (currDist < lastDist) { - lastDist = currDist; - selected = p; - } - } - return Optional.ofNullable(selected); - } - - @Override - public boolean matches(PlayerData player, ItemStack obj) { - return obj.getType() == material && hasRightClass(player); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java deleted file mode 100644 index 23c6b0d0..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java +++ /dev/null @@ -1,81 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source.type; - -import javax.annotation.Nullable; - -import org.bukkit.Location; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.Profession.ProfessionOption; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.PlayerClass; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; - -/** - * Atrocious API that really needs rewriting - * - * @author cympe - */ -public abstract class ExperienceSource { - private final Profession profession; - private PlayerClass profess; - - public ExperienceSource(Profession profession) { - this(profession, null); - } - - public ExperienceSource(PlayerClass profess) { - this(null, profess); - } - - public ExperienceSource(Profession profession, PlayerClass profess) { - this.profession = profession; - this.profess = profess; - } - - // TODO remove setter - public void setClass(PlayerClass profess) { - this.profess = profess; - } - - public boolean hasRightClass(PlayerData data) { - return profess == null || profess.equals(data.getProfess()); - } - - public boolean hasProfession() { - return profession != null; - } - - public boolean hasClass() { - return profess != null; - } - - public abstract ExperienceManager newManager(); - - public abstract boolean matches(PlayerData player, T obj); - - /** - * Gives experience to the right profession/class - * - * @param player Player to give exp to - * @param amount Amount of experience given - * @param hologramLocation If location is null the default location will be - * the player's torso - */ - public void giveExperience(PlayerData player, int amount, @Nullable Location hologramLocation) { - if (hasProfession()) { - hologramLocation = !profession.getOption(ProfessionOption.EXP_HOLOGRAMS) ? null - : hologramLocation == null ? getPlayerLocation(player) : hologramLocation; - player.getCollectionSkills().giveExperience(profession, amount, EXPSource.SOURCE, hologramLocation); - } else { - hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null - : hologramLocation == null ? getPlayerLocation(player) : hologramLocation; - player.giveExperience(amount, EXPSource.SOURCE, hologramLocation); - } - } - - private Location getPlayerLocation(PlayerData player) { - return player.isOnline() ? player.getPlayer().getLocation() : null; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java deleted file mode 100644 index 3cde4b3b..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/SpecificExperienceSource.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.Indyuce.mmocore.api.experience.source.type; - -import org.bukkit.Location; - -import net.Indyuce.mmocore.api.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; - -public abstract class SpecificExperienceSource extends ExperienceSource { - private final RandomAmount amount; - - /** - * Used to register experience sources with SPECIFIC experience outputs. - * Other experience sources like ENCHANT have their exp output depend on the - * enchanted item. ALCHEMY exp outputs depend on the potion crafted - */ - public SpecificExperienceSource(Profession profession, MMOLineConfig config) { - super(profession); - - config.validate("amount"); - amount = new RandomAmount(config.getString("amount")); - } - - public RandomAmount getAmount() { - return amount; - } - - public int rollAmount() { - return amount.calculateInt(); - } - - /** - * Used when a player needs to gain experience after performing the action - * corresponding to this exp source - * - * @param multiplier - * Used by the CraftItem experience source, multiplies the exp - * earned by a certain factor. When crafting an item, the - * multiplier is equal to the amount of items crafted - * @param loc - * Location used to display the exp hologram - */ - public void giveExperience(PlayerData player, int multiplier, Location loc) { - super.giveExperience(player, rollAmount() * multiplier, loc); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 493c09ad..0adb3bf1 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.load; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; import org.bukkit.configuration.ConfigurationSection; import net.Indyuce.mmocore.api.block.BlockType; @@ -16,17 +17,16 @@ import net.Indyuce.mmocore.api.droptable.dropitem.GoldDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.MMDropTableDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.NoteDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.VanillaDropItem; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.BrewPotionExperienceSource; -import net.Indyuce.mmocore.api.experience.source.CraftItemExperienceSource; -import net.Indyuce.mmocore.api.experience.source.EnchantItemExperienceSource; -import net.Indyuce.mmocore.api.experience.source.FishItemExperienceSource; -import net.Indyuce.mmocore.api.experience.source.KillMobExperienceSource; -import net.Indyuce.mmocore.api.experience.source.MineBlockExperienceSource; -import net.Indyuce.mmocore.api.experience.source.PlaceBlockExperienceSource; -import net.Indyuce.mmocore.api.experience.source.RepairItemExperienceSource; -import net.Indyuce.mmocore.api.experience.source.SmeltItemExperienceSource; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource; +import net.Indyuce.mmocore.experience.source.CraftItemExperienceSource; +import net.Indyuce.mmocore.experience.source.EnchantItemExperienceSource; +import net.Indyuce.mmocore.experience.source.FishItemExperienceSource; +import net.Indyuce.mmocore.experience.source.KillMobExperienceSource; +import net.Indyuce.mmocore.experience.source.MineBlockExperienceSource; +import net.Indyuce.mmocore.experience.source.PlaceBlockExperienceSource; +import net.Indyuce.mmocore.experience.source.RepairItemExperienceSource; +import net.Indyuce.mmocore.experience.source.SmeltItemExperienceSource; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.api.quest.objective.ClickonObjective; import net.Indyuce.mmocore.api.quest.objective.GoToObjective; import net.Indyuce.mmocore.api.quest.objective.KillMobObjective; @@ -129,33 +129,33 @@ public class DefaultMMOLoader extends MMOLoader { } @Override - public ExperienceSource loadExperienceSource(MMOLineConfig config, Profession profession) { + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { if (config.getKey().equals("fishitem")) - return new FishItemExperienceSource(profession, config); + return new FishItemExperienceSource(dispenser, config); if (config.getKey().equals("killmob")) - return new KillMobExperienceSource(profession, config); + return new KillMobExperienceSource(dispenser, config); if (config.getKey().equals("mineblock")) - return new MineBlockExperienceSource(profession, config); + return new MineBlockExperienceSource(dispenser, config); if (config.getKey().equals("placeblock")) - return new PlaceBlockExperienceSource(profession, config); + return new PlaceBlockExperienceSource(dispenser, config); if (config.getKey().equals("brewpotion")) - return new BrewPotionExperienceSource(profession, config); + return new BrewPotionExperienceSource(dispenser, config); if (config.getKey().equals("smeltitem")) - return new SmeltItemExperienceSource(profession, config); + return new SmeltItemExperienceSource(dispenser, config); if (config.getKey().equals("enchantitem")) - return new EnchantItemExperienceSource(profession, config); + return new EnchantItemExperienceSource(dispenser, config); if (config.getKey().equals("repairitem")) - return new RepairItemExperienceSource(profession, config); + return new RepairItemExperienceSource(dispenser, config); if (config.getKey().equals("craftitem")) - return new CraftItemExperienceSource(profession, config); + return new CraftItemExperienceSource(dispenser, config); return null; } diff --git a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java index 5d2a9ec7..b1bfebe2 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java @@ -1,43 +1,43 @@ package net.Indyuce.mmocore.api.load; -import org.bukkit.configuration.ConfigurationSection; - +import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.droptable.condition.Condition; import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.experience.provider.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; -import io.lumine.mythic.lib.api.MMOLineConfig; +import org.bukkit.configuration.ConfigurationSection; +/** + * MMOLoader was initially an interface but it is now a + * class so devs do not have to add a new method + * everytime the class is updated. + */ public class MMOLoader { - /* - * MMOLoader was initially an interface but it is now a class so devs do not - * have to add a new method everytime the class is updated. - */ - public Condition loadCondition(MMOLineConfig config) { - return null; - } + public Condition loadCondition(MMOLineConfig config) { + return null; + } - public Trigger loadTrigger(MMOLineConfig config) { - return null; - } + public Trigger loadTrigger(MMOLineConfig config) { + return null; + } - public DropItem loadDropItem(MMOLineConfig config) { - return null; - } + public DropItem loadDropItem(MMOLineConfig config) { + return null; + } - public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) { - return null; - } + public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) { + return null; + } - public ExperienceSource loadExperienceSource(MMOLineConfig config, Profession profession) { - return null; - } + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { + return null; + } - public BlockType loadBlockType(MMOLineConfig config) { - return null; - } + public BlockType loadBlockType(MMOLineConfig config) { + return null; + } } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index c43bc896..04282429 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -5,8 +5,6 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.Waypoint; import net.Indyuce.mmocore.api.event.*; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.experience.PlayerProfessions; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes; import net.Indyuce.mmocore.api.player.profess.PlayerClass; @@ -21,6 +19,8 @@ import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.quest.PlayerQuests; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect; +import net.Indyuce.mmocore.experience.EXPSource; +import net.Indyuce.mmocore.experience.PlayerProfessions; import net.Indyuce.mmocore.listener.SpellCast.SkillCasting; import net.Indyuce.mmocore.manager.SoundManager; import net.Indyuce.mmocore.skill.CasterMetadata; @@ -465,7 +465,7 @@ public class PlayerData extends OfflinePlayerData { * @param hologramLocation Location used to display the hologram. If it's null, no * hologram will be displayed */ - public void giveExperience(int value, EXPSource source, @Nullable Location hologramLocation) { + public void giveExperience(double value, EXPSource source, @Nullable Location hologramLocation) { if (hasReachedMaxLevel()) { setExperience(0); return; @@ -478,7 +478,7 @@ public class PlayerData extends OfflinePlayerData { value = MMOCore.plugin.boosterManager.calculateExp(null, value); value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100; - PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, value, source); + PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, (int) value, source); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return; 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 75617547..e696e7fb 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 @@ -7,18 +7,20 @@ 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.experience.ExpCurve; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; 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; import net.Indyuce.mmocore.api.player.profess.resource.ResourceHandler; import net.Indyuce.mmocore.api.player.stats.StatType; -import net.Indyuce.mmocore.skill.Skill; -import net.Indyuce.mmocore.skill.Skill.SkillInfo; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.util.math.particle.CastingParticle; +import net.Indyuce.mmocore.experience.ExpCurve; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.provider.MainExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.skill.Skill; +import net.Indyuce.mmocore.skill.Skill.SkillInfo; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.Validate; import org.bukkit.Material; @@ -33,292 +35,292 @@ import java.util.*; import java.util.logging.Level; public class PlayerClass extends PostLoadObject { - private final String name, id, actionBarFormat; - private final List description = new ArrayList<>(), attrDescription = new ArrayList<>(); - private final ItemStack icon; - private final Map options = new HashMap<>(); - private final ManaDisplayOptions manaDisplay; - private final int maxLevel, displayOrder; - private final ExpCurve expCurve; + private final String name, id, actionBarFormat; + private final List description = new ArrayList<>(), attrDescription = new ArrayList<>(); + private final ItemStack icon; + private final Map options = new HashMap<>(); + private final ManaDisplayOptions manaDisplay; + private final int maxLevel, displayOrder; + private final ExpCurve expCurve; - private final Map stats = new HashMap<>(); - private final Map skills = new LinkedHashMap<>(); - private final List subclasses = new ArrayList<>(); + private final Map stats = new HashMap<>(); + private final Map skills = new LinkedHashMap<>(); + private final List subclasses = new ArrayList<>(); - private final Map resourceHandlers = new HashMap<>(); - private final Map eventTriggers = new HashMap<>(); + private final Map resourceHandlers = new HashMap<>(); + private final Map eventTriggers = new HashMap<>(); - private final CastingParticle castParticle; + private final CastingParticle castParticle; - public PlayerClass(String id, FileConfiguration config) { - super(config); + public PlayerClass(String id, FileConfiguration config) { + super(config); - this.id = id.toUpperCase().replace("-", "_").replace(" ", "_"); + this.id = id.toUpperCase().replace("-", "_").replace(" ", "_"); - name = MythicLib.plugin.parseColors(config.getString("display.name", "INVALID DISPLAY NAME")); - icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER")); + name = MythicLib.plugin.parseColors(config.getString("display.name", "INVALID DISPLAY NAME")); + icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER")); - if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) - try { - ItemMeta meta = icon.getItemMeta(); - Field profileField = meta.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - GameProfile gp = new GameProfile(UUID.randomUUID(), null); - gp.getProperties().put("textures", new Property("textures", config.getString("display.texture"))); - profileField.set(meta, gp); - icon.setItemMeta(meta); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException - | SecurityException exception) { - throw new IllegalArgumentException("Could not apply playerhead texture: " + exception.getMessage()); - } + if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) + try { + ItemMeta meta = icon.getItemMeta(); + Field profileField = meta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + GameProfile gp = new GameProfile(UUID.randomUUID(), null); + gp.getProperties().put("textures", new Property("textures", config.getString("display.texture"))); + profileField.set(meta, gp); + icon.setItemMeta(meta); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException + | SecurityException exception) { + throw new IllegalArgumentException("Could not apply playerhead texture: " + exception.getMessage()); + } - for (String string : config.getStringList("display.lore")) - description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); - for (String string : config.getStringList("display.attribute-lore")) - attrDescription.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); - manaDisplay = config.contains("mana") ? new ManaDisplayOptions(config.getConfigurationSection("mana")) - : ManaDisplayOptions.DEFAULT; - maxLevel = config.getInt("max-level"); - displayOrder = config.getInt("display.order"); - actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null; + for (String string : config.getStringList("display.lore")) + description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); + for (String string : config.getStringList("display.attribute-lore")) + attrDescription.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); + manaDisplay = config.contains("mana") ? new ManaDisplayOptions(config.getConfigurationSection("mana")) + : ManaDisplayOptions.DEFAULT; + maxLevel = config.getInt("max-level"); + displayOrder = config.getInt("display.order"); + actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null; - expCurve = config.contains("exp-curve") - ? MMOCore.plugin.experience.getOrThrow( - config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) - : ExpCurve.DEFAULT; + expCurve = config.contains("exp-curve") + ? MMOCore.plugin.experience.getOrThrow( + config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) + : ExpCurve.DEFAULT; - if (config.contains("attributes")) - for (String key : config.getConfigurationSection("attributes").getKeys(false)) - try { - stats.put(StatType.valueOf(key.toUpperCase().replace("-", "_")), - new LinearValue(config.getConfigurationSection("attributes." + key))); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load stat info '" + key + "' from class '" - + id + "': " + exception.getMessage()); - } + if (config.contains("attributes")) + for (String key : config.getConfigurationSection("attributes").getKeys(false)) + try { + stats.put(StatType.valueOf(key.toUpperCase().replace("-", "_")), + new LinearValue(config.getConfigurationSection("attributes." + key))); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load stat info '" + key + "' from class '" + + id + "': " + exception.getMessage()); + } - if (config.contains("skills")) - for (String key : config.getConfigurationSection("skills").getKeys(false)) - try { - Validate.isTrue(MMOCore.plugin.skillManager.has(key), "Could not find skill " + key); - skills.put(key.toUpperCase(), MMOCore.plugin.skillManager.get(key) - .newSkillInfo(config.getConfigurationSection("skills." + key))); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill info '" + key + "' from class '" - + id + "': " + exception.getMessage()); - } + if (config.contains("skills")) + for (String key : config.getConfigurationSection("skills").getKeys(false)) + try { + Validate.isTrue(MMOCore.plugin.skillManager.has(key), "Could not find skill " + key); + skills.put(key.toUpperCase(), MMOCore.plugin.skillManager.get(key) + .newSkillInfo(config.getConfigurationSection("skills." + key))); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill info '" + key + "' from class '" + + id + "': " + exception.getMessage()); + } - castParticle = config.contains("cast-particle") - ? new CastingParticle(config.getConfigurationSection("cast-particle")) - : new CastingParticle(Particle.SPELL_INSTANT); + castParticle = config.contains("cast-particle") + ? new CastingParticle(config.getConfigurationSection("cast-particle")) + : new CastingParticle(Particle.SPELL_INSTANT); - if (config.contains("options")) - for (String key : config.getConfigurationSection("options").getKeys(false)) - try { - setOption(ClassOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")), - config.getBoolean("options." + key)); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, - "Could not load option '" + key + "' from class '" + key + "': " + exception.getMessage()); - } + if (config.contains("options")) + for (String key : config.getConfigurationSection("options").getKeys(false)) + try { + setOption(ClassOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")), + config.getBoolean("options." + key)); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, + "Could not load option '" + key + "' from class '" + key + "': " + exception.getMessage()); + } - if (config.contains("main-exp-sources")) - for (String key : config.getStringList("main-exp-sources")) - try { - ExperienceSource source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), - null); - source.setClass(this); - MMOCore.plugin.professionManager.registerExpSource(source); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '" - + id + "': " + exception.getMessage()); - } + if (config.contains("main-exp-sources")) { + ExperienceDispenser dispenser = new MainExperienceDispenser(this); + for (String key : config.getStringList("main-exp-sources")) + try { + ExperienceSource source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser); + MMOCore.plugin.professionManager.registerExpSource(source); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '" + + id + "': " + exception.getMessage()); + } + } - if (config.contains("triggers")) - for (String key : config.getConfigurationSection("triggers").getKeys(false)) { - try { - String format = key.toLowerCase().replace("_", "-").replace(" ", "-"); - eventTriggers.put(format, new EventTrigger(format, config.getStringList("triggers." + key))); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] " + exception.getMessage()); - } - } + if (config.contains("triggers")) + for (String key : config.getConfigurationSection("triggers").getKeys(false)) { + try { + String format = key.toLowerCase().replace("_", "-").replace(" ", "-"); + eventTriggers.put(format, new EventTrigger(format, config.getStringList("triggers." + key))); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] " + exception.getMessage()); + } + } - /* - * must make sure all the resourceHandlers are registered when the placer class - * is initialized. - */ - for (PlayerResource resource : PlayerResource.values()) { - if (config.isConfigurationSection("resource." + resource.name().toLowerCase())) - try { - resourceHandlers.put(resource, new ResourceHandler(resource, - config.getConfigurationSection("resource." + resource.name().toLowerCase()))); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load special resource regen for " - + resource.name() + ": " + exception.getMessage()); - resourceHandlers.put(resource, new ResourceHandler(resource)); - } - else - resourceHandlers.put(resource, new ResourceHandler(resource)); - } - } + /* + * must make sure all the resourceHandlers are registered when the placer class + * is initialized. + */ + for (PlayerResource resource : PlayerResource.values()) { + if (config.isConfigurationSection("resource." + resource.name().toLowerCase())) + try { + resourceHandlers.put(resource, new ResourceHandler(resource, + config.getConfigurationSection("resource." + resource.name().toLowerCase()))); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load special resource regen for " + + resource.name() + ": " + exception.getMessage()); + resourceHandlers.put(resource, new ResourceHandler(resource)); + } + else + resourceHandlers.put(resource, new ResourceHandler(resource)); + } + } - /* - * used to generate display class - */ - public PlayerClass(String id, String name, Material material) { - super(null); + /* + * used to generate display class + */ + public PlayerClass(String id, String name, Material material) { + super(null); - this.id = id; - this.name = name; - manaDisplay = ManaDisplayOptions.DEFAULT; - maxLevel = 0; - displayOrder = 0; - expCurve = ExpCurve.DEFAULT; - castParticle = new CastingParticle(Particle.SPELL_INSTANT); - actionBarFormat = ""; + this.id = id; + this.name = name; + manaDisplay = ManaDisplayOptions.DEFAULT; + maxLevel = 0; + displayOrder = 0; + expCurve = ExpCurve.DEFAULT; + castParticle = new CastingParticle(Particle.SPELL_INSTANT); + actionBarFormat = ""; - this.icon = new ItemStack(material); - setOption(ClassOption.DISPLAY, false); - setOption(ClassOption.DEFAULT, false); + this.icon = new ItemStack(material); + setOption(ClassOption.DISPLAY, false); + setOption(ClassOption.DEFAULT, false); - for (PlayerResource resource : PlayerResource.values()) - resourceHandlers.put(resource, new ResourceHandler(resource)); - } + for (PlayerResource resource : PlayerResource.values()) + resourceHandlers.put(resource, new ResourceHandler(resource)); + } - @Override - protected void whenPostLoaded(ConfigurationSection config) { - if (config.contains("subclasses")) - for (String key : config.getConfigurationSection("subclasses").getKeys(false)) - try { - subclasses.add(new Subclass( - MMOCore.plugin.classManager - .getOrThrow(key.toUpperCase().replace("-", "_").replace(" ", "_")), - config.getInt("subclasses." + key))); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load subclass '" + key + "' from class '" - + getId() + "': " + exception.getMessage()); - } - } + @Override + protected void whenPostLoaded(ConfigurationSection config) { + if (config.contains("subclasses")) + for (String key : config.getConfigurationSection("subclasses").getKeys(false)) + try { + subclasses.add(new Subclass( + MMOCore.plugin.classManager + .getOrThrow(key.toUpperCase().replace("-", "_").replace(" ", "_")), + config.getInt("subclasses." + key))); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load subclass '" + key + "' from class '" + + getId() + "': " + exception.getMessage()); + } + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public ManaDisplayOptions getManaDisplay() { - return manaDisplay; - } + public ManaDisplayOptions getManaDisplay() { + return manaDisplay; + } - public ResourceHandler getHandler(PlayerResource resource) { - return resourceHandlers.get(resource); - } + public ResourceHandler getHandler(PlayerResource resource) { + return resourceHandlers.get(resource); + } - public int getMaxLevel() { - return maxLevel; - } + public int getMaxLevel() { + return maxLevel; + } - public int getDisplayOrder() { - return displayOrder; - } + public int getDisplayOrder() { + return displayOrder; + } - public ExpCurve getExpCurve() { - return expCurve; - } + public ExpCurve getExpCurve() { + return expCurve; + } - public ItemStack getIcon() { - return icon.clone(); - } + public ItemStack getIcon() { + return icon.clone(); + } - public CastingParticle getCastParticle() { - return castParticle; - } + public CastingParticle getCastParticle() { + return castParticle; + } - public List getDescription() { - return description; - } + public List getDescription() { + return description; + } - public List getAttributeDescription() { - return attrDescription; - } + public List getAttributeDescription() { + return attrDescription; + } - public void setOption(ClassOption option, boolean value) { - options.put(option, value); - } + public void setOption(ClassOption option, boolean value) { + options.put(option, value); + } - public boolean hasOption(ClassOption option) { - return options.containsKey(option) ? options.get(option) : option.getDefault(); - } + public boolean hasOption(ClassOption option) { + return options.containsKey(option) ? options.get(option) : option.getDefault(); + } - public void setStat(StatType type, double base, double perLevel) { - stats.put(type, new LinearValue(base, perLevel)); - } + public void setStat(StatType type, double base, double perLevel) { + stats.put(type, new LinearValue(base, perLevel)); + } - public double calculateStat(StatType stat, int level) { - return getStatInfo(stat).calculate(level); - } + public double calculateStat(StatType stat, int level) { + return getStatInfo(stat).calculate(level); + } - public List getSubclasses() { - return subclasses; - } + public List getSubclasses() { + return subclasses; + } - public boolean hasSkill(Skill skill) { - return hasSkill(skill.getId()); - } + public boolean hasSkill(Skill skill) { + return hasSkill(skill.getId()); + } - public boolean hasSkill(String id) { - return skills.containsKey(id); - } + public boolean hasSkill(String id) { + return skills.containsKey(id); + } - public SkillInfo getSkill(Skill skill) { - return getSkill(skill.getId()); - } + public SkillInfo getSkill(Skill skill) { + return getSkill(skill.getId()); + } - /* - * reduces map checkups when skills are being checked on events that are - * commonly called like EntityDamageEvent or regen events. - */ - public Optional findSkill(Skill skill) { - return skills.containsKey(skill.getId()) ? Optional.of(skills.get(skill.getId())) : Optional.empty(); - } + /* + * reduces map checkups when skills are being checked on events that are + * commonly called like EntityDamageEvent or regen events. + */ + public Optional findSkill(Skill skill) { + return skills.containsKey(skill.getId()) ? Optional.of(skills.get(skill.getId())) : Optional.empty(); + } - public SkillInfo getSkill(String id) { - return skills.get(id); - } + public SkillInfo getSkill(String id) { + return skills.get(id); + } - public Set getEventTriggers() { - return eventTriggers.keySet(); - } + public Set getEventTriggers() { + return eventTriggers.keySet(); + } - public boolean hasEventTriggers(String name) { - return eventTriggers.containsKey(name); - } + public boolean hasEventTriggers(String name) { + return eventTriggers.containsKey(name); + } - public EventTrigger getEventTriggers(String name) { - return eventTriggers.get(name); - } + public EventTrigger getEventTriggers(String name) { + return eventTriggers.get(name); + } - public Collection getSkills() { - return skills.values(); - } + public Collection getSkills() { + return skills.values(); + } - private LinearValue getStatInfo(StatType type) { - return stats.containsKey(type) ? stats.get(type) : type.getDefault(); - } + private LinearValue getStatInfo(StatType type) { + return stats.containsKey(type) ? stats.get(type) : type.getDefault(); + } - @Override - public boolean equals(Object obj) { - return obj instanceof PlayerClass && ((PlayerClass) obj).id.equals(id); - } + @Override + public boolean equals(Object obj) { + return obj instanceof PlayerClass && ((PlayerClass) obj).id.equals(id); + } - public String getActionBar() { - return actionBarFormat; - } + public String getActionBar() { + return actionBarFormat; + } - public boolean hasActionBar() { - return actionBarFormat != null; - } + public boolean hasActionBar() { + return actionBarFormat != null; + } } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java b/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java index 095b9a2a..1e82fe23 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/stats/StatType.java @@ -2,7 +2,7 @@ package net.Indyuce.mmocore.api.player.stats; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigFile; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import io.lumine.mythic.lib.MythicLib; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/Quest.java b/src/main/java/net/Indyuce/mmocore/api/quest/Quest.java index 4739cf55..fef02f33 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/Quest.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/Quest.java @@ -12,7 +12,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.quest.objective.Objective; import io.lumine.mythic.lib.api.MMOLineConfig; 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 5ac82293..330d774b 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 @@ -3,9 +3,9 @@ package net.Indyuce.mmocore.api.quest.trigger; import org.apache.commons.lang.Validate; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.experience.ExperienceInfo; -import net.Indyuce.mmocore.api.experience.Profession; +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; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java index 4cdbdacb..2625695c 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java @@ -8,9 +8,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.experience.PlayerProfessions; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.EXPSource; +import net.Indyuce.mmocore.experience.PlayerProfessions; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.command.CommandVerbose; import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java index d3e83797..7a9c1081 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java @@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode; import io.lumine.mythic.lib.mmolibcommands.api.Parameter; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java index 2c894aad..4f9c480c 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java @@ -9,9 +9,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.experience.PlayerProfessions; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.EXPSource; +import net.Indyuce.mmocore.experience.PlayerProfessions; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot; import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java index a942638c..9d96d8c6 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java @@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes.AttributeInstance; import net.Indyuce.mmocore.command.CommandVerbose; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/booster/CreateCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/booster/CreateCommandTreeNode.java index 0ab2332a..b06865f5 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/booster/CreateCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/booster/CreateCommandTreeNode.java @@ -9,8 +9,8 @@ import org.bukkit.command.CommandSender; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; -import net.Indyuce.mmocore.api.experience.Booster; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Booster; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot; import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode; import io.lumine.mythic.lib.mmolibcommands.api.Parameter; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/booster/ListCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/booster/ListCommandTreeNode.java index 73363fa9..11ff1c0f 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/booster/ListCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/booster/ListCommandTreeNode.java @@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Booster; +import net.Indyuce.mmocore.experience.Booster; import net.Indyuce.mmocore.api.util.math.format.DelayFormat; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode; diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/booster/RemoveCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/booster/RemoveCommandTreeNode.java index c10cd4dd..3f989c0f 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/booster/RemoveCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/booster/RemoveCommandTreeNode.java @@ -7,7 +7,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Booster; +import net.Indyuce.mmocore.experience.Booster; import io.lumine.mythic.lib.mmolibcommands.api.CommandTreeNode; import io.lumine.mythic.lib.mmolibcommands.api.Parameter; diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java index be2157d4..9f162b6b 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java @@ -1,9 +1,10 @@ package net.Indyuce.mmocore.comp.mythicmobs; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; import org.bukkit.configuration.ConfigurationSection; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.experience.Profession; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.api.load.MMOLoader; import net.Indyuce.mmocore.api.quest.objective.Objective; import net.Indyuce.mmocore.api.quest.trigger.Trigger; @@ -37,12 +38,12 @@ public class MythicMobsMMOLoader extends MMOLoader { } @Override - public ExperienceSource loadExperienceSource(MMOLineConfig config, Profession profession) { + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { if (config.getKey().equalsIgnoreCase("killmythicmob")) - return new KillMythicMobExperienceSource(profession, config); + return new KillMythicMobExperienceSource(dispenser, config); if (config.getKey().equalsIgnoreCase("killmythicfaction")) - return new KillMythicFactionExperienceSource(profession, config); + return new KillMythicFactionExperienceSource(dispenser, config); return null; } diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java index 7c9999c9..88e57d22 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicFactionExperienceSource.java @@ -1,48 +1,47 @@ package net.Indyuce.mmocore.comp.mythicmobs.load; +import io.lumine.mythic.lib.api.MMOLineConfig; +import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - public class KillMythicFactionExperienceSource extends SpecificExperienceSource { - private final String factionName; + private final String factionName; - public KillMythicFactionExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); + public KillMythicFactionExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); - config.validate("name"); - factionName = config.getString("name"); - } + config.validate("name"); + factionName = config.getString("name"); + } - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - @EventHandler - public void a(MythicMobDeathEvent event) { - Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { - if (!event.getEntity().isDead()) return; - if (!event.getMob().hasFaction()) return; - if (!(event.getKiller() instanceof Player) || event.getKiller().hasMetadata("NPC")) return; + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + @EventHandler + public void a(MythicMobDeathEvent event) { + Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { + if (!event.getEntity().isDead()) return; + if (!event.getMob().hasFaction()) return; + if (!(event.getKiller() instanceof Player) || event.getKiller().hasMetadata("NPC")) return; - PlayerData data = PlayerData.get((Player) event.getKiller()); - for (KillMythicFactionExperienceSource source : getSources()) - if (source.matches(data, event.getMob().getFaction())) - source.giveExperience(data, 1, event.getEntity().getLocation()); - }, 2); - } - }; - } + PlayerData data = PlayerData.get((Player) event.getKiller()); + for (KillMythicFactionExperienceSource source : getSources()) + if (source.matches(data, event.getMob().getFaction())) + source.giveExperience(data, 1, event.getEntity().getLocation()); + }, 2); + } + }; + } - @Override - public boolean matches(PlayerData player, String name) { - return hasRightClass(player) && name.equals(factionName); - } + @Override + public boolean matchesParameter(PlayerData player, String name) { + return name.equals(factionName); + } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java index 537da125..c23e8b06 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/load/KillMythicMobExperienceSource.java @@ -1,47 +1,46 @@ package net.Indyuce.mmocore.comp.mythicmobs.load; +import io.lumine.mythic.lib.api.MMOLineConfig; +import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.manager.profession.ExperienceManager; -import io.lumine.mythic.lib.api.MMOLineConfig; - public class KillMythicMobExperienceSource extends SpecificExperienceSource { - private final String internalName; + private final String internalName; - public KillMythicMobExperienceSource(Profession profession, MMOLineConfig config) { - super(profession, config); + public KillMythicMobExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); - config.validate("type"); - internalName = config.getString("type"); - } + config.validate("type"); + internalName = config.getString("type"); + } - @Override - public ExperienceManager newManager() { - return new ExperienceManager() { - @EventHandler - public void a(MythicMobDeathEvent event) { - Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { - if (!event.getEntity().isDead()) return; - if (!(event.getKiller() instanceof Player) || event.getKiller().hasMetadata("NPC")) return; + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + @EventHandler + public void a(MythicMobDeathEvent event) { + Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { + if (!event.getEntity().isDead()) return; + if (!(event.getKiller() instanceof Player) || event.getKiller().hasMetadata("NPC")) return; - PlayerData data = PlayerData.get((Player) event.getKiller()); - for (KillMythicMobExperienceSource source : getSources()) - if (source.matches(data, event.getMobType().getInternalName())) - source.giveExperience(data, 1, event.getEntity().getLocation()); - }, 2); - } - }; - } + PlayerData data = PlayerData.get((Player) event.getKiller()); + for (KillMythicMobExperienceSource source : getSources()) + if (source.matches(data, event.getMobType().getInternalName())) + source.giveExperience(data, 1, event.getEntity().getLocation()); + }, 2); + } + }; + } - @Override - public boolean matches(PlayerData player, String name) { - return hasRightClass(player) && name.equals(internalName); - } + @Override + public boolean matchesParameter(PlayerData player, String name) { + return name.equals(internalName); + } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java index b2a2b4dd..90196498 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java +++ b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java @@ -4,8 +4,8 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.util.AltChar; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.PlayerProfessions; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.PlayerProfessions; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.quest.PlayerQuests; diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/Booster.java b/src/main/java/net/Indyuce/mmocore/experience/Booster.java similarity index 98% rename from src/main/java/net/Indyuce/mmocore/api/experience/Booster.java rename to src/main/java/net/Indyuce/mmocore/experience/Booster.java index 6df11403..c15d6928 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/Booster.java +++ b/src/main/java/net/Indyuce/mmocore/experience/Booster.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.experience; +package net.Indyuce.mmocore.experience; import java.util.Objects; import java.util.UUID; diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java b/src/main/java/net/Indyuce/mmocore/experience/EXPSource.java similarity index 64% rename from src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java rename to src/main/java/net/Indyuce/mmocore/experience/EXPSource.java index 2c606d83..a8fef063 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/EXPSource.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.experience; +package net.Indyuce.mmocore.experience; public enum EXPSource { SOURCE, diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/ExpCurve.java b/src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java similarity index 95% rename from src/main/java/net/Indyuce/mmocore/api/experience/ExpCurve.java rename to src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java index 98619282..6769099f 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/ExpCurve.java +++ b/src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java @@ -1,76 +1,76 @@ -package net.Indyuce.mmocore.api.experience; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang.Validate; - -public class ExpCurve { - private final String id; - - /** - * Experience needed to level up. Different professions or classes can have - * different exp curves so that it is easier to balance. - */ - private final List experience = new ArrayList<>(); - - /** - * Purely arbitrary but MMOCore needs a default exp curve for everything - * otherwise there might be divisions by 0 when trying to update the vanilla - * exp bar which requires a 0.0 -> 1.0 float as parameter - */ - public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500); - - /** - * Reads an exp curve from a text file, one line after the other. Each exp - * value has to be the only thing written on every line - * - * @param file Text file to read data from - * @throws IOException IO exception when reading file - */ - public ExpCurve(File file) throws IOException { - this.id = file.getName().replace(".txt", "").toLowerCase().replace("_", "-").replace(" ", "-"); - - BufferedReader reader = new BufferedReader(new FileReader(file)); - String readLine; - while ((readLine = reader.readLine()) != null) - experience.add(Integer.valueOf(readLine)); - reader.close(); - - Validate.isTrue(!experience.isEmpty(), "There must be at least one exp value in your exp curve"); - } - - /** - * Public constructor for external plugins - * - * @param id Some unique identifier to let other plugin features refer - * to your exp curve. - * @param values The exp values, at to be at least one or the constructor - * will throw an error - */ - public ExpCurve(String id, int... values) { - this.id = id; - for (int value : values) - experience.add(value); - Validate.isTrue(!experience.isEmpty(), "There must be at least one exp value in your exp curve"); - } - - public String getId() { - return id; - } - - /** - * @param level Level being reached by some player - * @return Experience needed to reach provided level. The level serves - * an index for a list checkup. If the level is higher than - * the list size, it just returns the last value of the list - */ - public int getExperience(int level) { - Validate.isTrue(level > 0, "Level must be stricly positive"); - return experience.get(Math.min(level, experience.size()) - 1); - } -} +package net.Indyuce.mmocore.experience; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.Validate; + +public class ExpCurve { + private final String id; + + /** + * Experience needed to level up. Different professions or classes can have + * different exp curves so that it is easier to balance. + */ + private final List experience = new ArrayList<>(); + + /** + * Purely arbitrary but MMOCore needs a default exp curve for everything + * otherwise there might be divisions by 0 when trying to update the vanilla + * exp bar which requires a 0.0 -> 1.0 float as parameter + */ + public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500); + + /** + * Reads an exp curve from a text file, one line after the other. Each exp + * value has to be the only thing written on every line + * + * @param file Text file to read data from + * @throws IOException IO exception when reading file + */ + public ExpCurve(File file) throws IOException { + this.id = file.getName().replace(".txt", "").toLowerCase().replace("_", "-").replace(" ", "-"); + + BufferedReader reader = new BufferedReader(new FileReader(file)); + String readLine; + while ((readLine = reader.readLine()) != null) + experience.add(Integer.valueOf(readLine)); + reader.close(); + + Validate.isTrue(!experience.isEmpty(), "There must be at least one exp value in your exp curve"); + } + + /** + * Public constructor for external plugins + * + * @param id Some unique identifier to let other plugin features refer + * to your exp curve. + * @param values The exp values, at to be at least one or the constructor + * will throw an error + */ + public ExpCurve(String id, int... values) { + this.id = id; + for (int value : values) + experience.add(value); + Validate.isTrue(!experience.isEmpty(), "There must be at least one exp value in your exp curve"); + } + + public String getId() { + return id; + } + + /** + * @param level Level being reached by some player + * @return Experience needed to reach provided level. The level serves + * an index for a list checkup. If the level is higher than + * the list size, it just returns the last value of the list + */ + public int getExperience(int level) { + Validate.isTrue(level > 0, "Level must be stricly positive"); + return experience.get(Math.min(level, experience.size()) - 1); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/ExperienceInfo.java b/src/main/java/net/Indyuce/mmocore/experience/ExperienceInfo.java similarity index 87% rename from src/main/java/net/Indyuce/mmocore/api/experience/ExperienceInfo.java rename to src/main/java/net/Indyuce/mmocore/experience/ExperienceInfo.java index 51cc80b5..18113069 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/ExperienceInfo.java +++ b/src/main/java/net/Indyuce/mmocore/experience/ExperienceInfo.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.experience; +package net.Indyuce.mmocore.experience; public class ExperienceInfo { private final Profession profess; diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java similarity index 95% rename from src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java rename to src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index e9264b34..4392954c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.api.experience; +package net.Indyuce.mmocore.experience; import com.google.gson.Gson; import com.google.gson.JsonElement; @@ -128,7 +128,7 @@ public class PlayerProfessions { return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel(); } - public void giveExperience(Profession profession, int value, EXPSource source, @Nullable Location hologramLocation) { + public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation) { if (hasReachedMaxLevel(profession)) { setExperience(profession, 0); return; @@ -140,12 +140,12 @@ public class PlayerProfessions { if (hologramLocation != null && playerData.isOnline()) MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); - PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source); + PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, (int) value, source); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return; - exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + value : value); + exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + event.getExperience() : event.getExperience()); int needed, exp, level, oldLevel = getLevel(profession); /* diff --git a/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/experience/Profession.java new file mode 100644 index 00000000..3c939d84 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -0,0 +1,191 @@ +package net.Indyuce.mmocore.experience; + +import io.lumine.mythic.lib.MythicLib; +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.util.math.formula.LinearValue; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.provider.ProfessionExperienceDispenser; +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.potion.PotionType; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; + +public class Profession extends PostLoadObject { + private final String id, name; + private final ExpCurve expCurve; + private final int maxLevel; + private final Map options = new HashMap<>(); + + /* + * experience given to the main player level whenever he levels up this + * profession + */ + private final LinearValue experience; + + public Profession(String id, FileConfiguration config) { + super(config); + + this.id = id.toLowerCase().replace("_", "-").replace(" ", "-"); + this.name = config.getString("name"); + Validate.notNull(name, "Could not load name"); + + expCurve = config.contains("exp-curve") + ? MMOCore.plugin.experience.getOrThrow(config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) + : ExpCurve.DEFAULT; + experience = new LinearValue(config.getConfigurationSection("experience")); + + if (config.contains("options")) + for (String key : config.getConfigurationSection("options").getKeys(false)) + try { + ProfessionOption option = ProfessionOption.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); + options.put(option, config.getBoolean("options." + key)); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, + "Could not load option '" + key + "' from profession '" + id + "': " + exception.getMessage()); + } + + maxLevel = config.getInt("max-level"); + + if (config.contains("exp-sources")) { + ExperienceDispenser dispenser = new ProfessionExperienceDispenser(this); + for (String key : config.getStringList("exp-sources")) + try { + MMOCore.plugin.professionManager.registerExpSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser)); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, + "Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage()); + } + } + } + + /* + * drop tables must be loaded after professions are initialized + */ + @Override + protected void whenPostLoaded(ConfigurationSection config) { + + if (config.contains("on-fish")) + MMOCore.plugin.fishingManager.loadDropTables(config.getConfigurationSection("on-fish")); + + if (config.contains("on-mine")) + MMOCore.plugin.mineManager.loadDropTables(config.getConfigurationSection("on-mine")); + + if (config.contains("alchemy-experience")) { + + MMOCore.plugin.alchemyManager.splash = 1 + config.getDouble("alchemy-experience.special.splash") / 100; + MMOCore.plugin.alchemyManager.lingering = 1 + config.getDouble("alchemy-experience.special.lingering") / 100; + MMOCore.plugin.alchemyManager.extend = 1 + config.getDouble("alchemy-experience.special.extend") / 100; + MMOCore.plugin.alchemyManager.upgrade = 1 + config.getDouble("alchemy-experience.special.upgrade") / 100; + + for (String key : config.getConfigurationSection("alchemy-experience.effects").getKeys(false)) + try { + PotionType type = PotionType.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); + MMOCore.plugin.alchemyManager.registerBaseExperience(type, config.getDouble("alchemy-experience.effects." + key)); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read potion type from " + key); + } + } + + if (config.contains("base-enchant-exp")) + for (String key : config.getConfigurationSection("base-enchant-exp").getKeys(false)) + try { + Enchantment enchant = MythicLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_")); + MMOCore.plugin.enchantManager.registerBaseExperience(enchant, config.getDouble("base-enchant-exp." + key)); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read enchant from " + key); + } + + if (config.contains("repair-exp")) + for (String key : config.getConfigurationSection("repair-exp").getKeys(false)) + try { + Material material = Material.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); + MMOCore.plugin.smithingManager.registerBaseExperience(material, config.getDouble("repair-exp." + key)); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not read material from " + key); + } + + // if (config.contains("effect-weight")) + // for (String key : + // config.getConfigurationSection("effect-weight").getKeys(false)) + // try { + // MMOCore.plugin.alchemyManager.registerEffectWeight(PotionEffectType.getByName(key.toUpperCase().replace("-", + // "_").replace(" ", "_")), config.getDouble("effect-weight." + key)); + // } catch (IllegalArgumentException exception) { + // MMOCore.log(Level.WARNING, "[PlayerProfessions:" + id + "] Could not + // read + // potion effect type from " + key); + // } + } + + public boolean getOption(ProfessionOption option) { + return options.getOrDefault(option, option.getDefault()); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public ExpCurve getExpCurve() { + return expCurve; + } + + public int getMaxLevel() { + return maxLevel; + } + + public boolean hasMaxLevel() { + return maxLevel > 0; + } + + public int calculateExperience(int x) { + return (int) experience.calculate(x); + } + + public LinearValue getExperience() { + return experience; + } + + public static enum ProfessionOption { + + /** + * When disabled, removes exp holograms when mined + */ + EXP_HOLOGRAMS(true); + + private final boolean def; + + private ProfessionOption(boolean def) { + this.def = def; + } + + public boolean getDefault() { + return def; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Profession that = (Profession) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java new file mode 100644 index 00000000..29af833c --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java @@ -0,0 +1,30 @@ +package net.Indyuce.mmocore.experience.provider; + +import net.Indyuce.mmocore.api.player.PlayerData; +import org.bukkit.Location; +import org.jetbrains.annotations.Nullable; + +/** + * Used to differenciate between the main class experience + * and experience given in a specific profession + */ +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 hologramLocation Location of displayed hologram, nothing + * is displayed if it's null + */ + void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation); + + boolean matches(PlayerData playerData); + + default Location getPlayerLocation(PlayerData player) { + return player.isOnline() ? player.getPlayer().getLocation() : null; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java new file mode 100644 index 00000000..b3f3918c --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java @@ -0,0 +1,29 @@ +package net.Indyuce.mmocore.experience.provider; + +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 MainExperienceDispenser implements ExperienceDispenser { + private final PlayerClass profess; + + public MainExperienceDispenser(PlayerClass profess) { + this.profess = profess; + } + + @Override + public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation) { + hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null + : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; + playerData.giveExperience(experience, EXPSource.SOURCE, hologramLocation); + + } + + @Override + public boolean matches(PlayerData playerData) { + return playerData.getProfess().equals(profess); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java new file mode 100644 index 00000000..674afe88 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java @@ -0,0 +1,27 @@ +package net.Indyuce.mmocore.experience.provider; + +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) { + hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null + : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; + playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation); + } + + @Override + public boolean matches(PlayerData playerData) { + return true; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/BrewPotionExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/BrewPotionExperienceSource.java new file mode 100644 index 00000000..342faea4 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/BrewPotionExperienceSource.java @@ -0,0 +1,170 @@ +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.source.type.ExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.BrewEvent; +import org.bukkit.inventory.BrewerInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class BrewPotionExperienceSource extends ExperienceSource { + private final List types = new ArrayList<>(); + + public BrewPotionExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser); + + if (config.contains("effect")) + for (String key : config.getString("effect").split(",")) + types.add(PotionType.valueOf(key.toUpperCase().replace("-", "_"))); + } + + @Override + public boolean matchesParameter(PlayerData player, PotionMeta meta) { + return types.isEmpty() || new ArrayList<>(types).stream().anyMatch(type -> meta.getBasePotionData().getType() == type); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void a(BrewEvent event) { + Optional playerOpt = getNearbyPlayer(event.getBlock().getLocation()); + if (!playerOpt.isPresent()) + return; + + final ItemStack found = findPotion(event.getContents()); + if (found != null) + Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, () -> { + ItemStack brewn = findPotion(event.getContents()); + if (brewn == null) + return; + + PlayerData data = PlayerData.get(playerOpt.get()); + for (BrewPotionExperienceSource source : getSources()) + if (source.matches(data, (PotionMeta) brewn.getItemMeta())) + new PotionUpgrade(found, brewn).process(data.getPlayer()); + }); + } + }; + } + + private ItemStack findPotion(BrewerInventory inv) { + for (int j = 0; j < 3; j++) { + ItemStack item = inv.getItem(j); + if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) + return item; + } + return null; + } + + private Optional getNearbyPlayer(Location loc) { + return loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < 100).findAny(); + } + + public class PotionUpgrade { + + /* + * if the potion was extended using redstone or upgraded using + * glowstone. PREPARE corresponds to when a water bottle is prepared for + * later recipes using NETHER STALK + */ + private double exp; + + // private final PotionMeta old, brewn; + + public PotionUpgrade(ItemStack old, ItemStack brewn) { + this(old.getType(), (PotionMeta) old.getItemMeta(), brewn.getType(), (PotionMeta) brewn.getItemMeta()); + } + + public PotionUpgrade(Material oldPot, PotionMeta old, Material brewnPot, PotionMeta brewn) { + + // this.old = old; + // this.brewn = brewn; + + /* + * calculate base exp + */ + + exp += MMOCore.plugin.alchemyManager.getBaseExperience(brewn.getBasePotionData().getType()); + + // !old.getBasePotionData().getType().isUpgradeable() && + // brewn.getBasePotionData().getType().isUpgradeable(), + // + // !old.getBasePotionData().isExtended() && + // brewn.getBasePotionData().isExtended(), + // + // !old.getBasePotionData().isUpgraded() && + // brewn.getBasePotionData().isUpgraded()); + + /* + * EXP modifiers based on brewing conditions + */ + if (oldPot == Material.POTION && brewnPot == Material.SPLASH_POTION) + exp *= MMOCore.plugin.alchemyManager.splash; + if (oldPot == Material.POTION && brewnPot == Material.LINGERING_POTION) + exp *= MMOCore.plugin.alchemyManager.lingering; + if (!old.getBasePotionData().isExtended() && brewn.getBasePotionData().isExtended()) + exp *= MMOCore.plugin.alchemyManager.extend; + if (!old.getBasePotionData().isUpgraded() && brewn.getBasePotionData().isUpgraded()) + exp *= MMOCore.plugin.alchemyManager.upgrade; + } + + // private Map mapEffectDurations() { + // Map map = new HashMap<>(); + // + // /* + // * potion level, plus the potion gained duration (max 0 so it does + // * not give negative EXP), multiplied by the potion effect weight. + // */ + // brewn.getCustomEffects().forEach(effect -> map.put(effect.getType(), + // + // (effect.getAmplifier() + 1 + (double) Math.max(0, + // effect.getDuration() - getPotionEffect(old, + // effect.getType()).orElseGet(() -> new + // PotionEffect(PotionEffectType.SPEED, 0, 0)).getDuration()) / 60.) + // + // * MMOCore.plugin.alchemyManager.getWeight(effect.getType()))); + // + // return map; + // } + + // private int getTotal(Map map) { + // double t = 0; + // for (double d : map.values()) + // t += d; + // return (int) t; + // } + + // private Optional getPotionEffect(PotionMeta meta, + // PotionEffectType type) { + // return meta.getCustomEffects().stream().filter(effect -> + // effect.getType() == type).findFirst(); + // } + + public void process(Player player) { + + /* + * calculate extra exp due to extra effects + */ + // exp += getTotal(mapEffectDurations()); + + getDispenser().giveExperience(PlayerData.get(player), (int) exp, null); + } + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java new file mode 100644 index 00000000..edbe0363 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java @@ -0,0 +1,44 @@ +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.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.inventory.InventoryAction; + +public class CraftItemExperienceSource extends SpecificExperienceSource { + public final Material material; + + public CraftItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + + config.validate("type"); + material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void a(CraftItemEvent event) { + if (event.getAction() == InventoryAction.NOTHING || + event.getInventory().getResult() == null) return; + PlayerData data = PlayerData.get((Player) event.getWhoClicked()); + for (CraftItemExperienceSource source : getSources()) + if (source.matches(data, event.getInventory().getResult().getType())) + source.giveExperience(data, event.getInventory().getResult().getAmount(), event.getInventory().getLocation()); + } + }; + } + + @Override + public boolean matchesParameter(PlayerData player, Material obj) { + return material == obj; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/EnchantItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/EnchantItemExperienceSource.java new file mode 100644 index 00000000..db65ebd2 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/EnchantItemExperienceSource.java @@ -0,0 +1,62 @@ +package net.Indyuce.mmocore.experience.source; + +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.enchantment.EnchantItemEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EnchantItemExperienceSource extends ExperienceSource { + private final List enchants = new ArrayList<>(); + + public EnchantItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser); + + if (config.contains("enchant")) + for (String key : config.getString("enchant").split(",")) + enchants.add(MythicLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_"))); + } + + @Override + public boolean matchesParameter(PlayerData player, Void v) { + return true; + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void a(EnchantItemEvent event) { + PlayerData player = PlayerData.get(event.getEnchanter()); + for (EnchantItemExperienceSource source : getSources()) + if (source.matches(player, null)) { + Map ench = new HashMap<>(event.getEnchantsToAdd()); + + if (!source.enchants.isEmpty()) + ench.keySet().removeIf(enchantment -> !source.enchants.contains(enchantment)); + + if (ench.isEmpty()) + continue; + + double exp = 0; + for (Entry entry : ench.entrySet()) + exp += MMOCore.plugin.enchantManager.getBaseExperience(entry.getKey()) * entry.getValue(); + getDispenser().giveExperience(player, (int) exp, event.getEnchantBlock().getLocation()); + } + } + }; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/FishItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/FishItemExperienceSource.java new file mode 100644 index 00000000..2be0e14f --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/FishItemExperienceSource.java @@ -0,0 +1,50 @@ +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.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.Material; +import org.bukkit.entity.Item; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerFishEvent.State; +import org.bukkit.inventory.ItemStack; + +public class FishItemExperienceSource extends SpecificExperienceSource { + private final Material material; + + public FishItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + + config.validate("type"); + material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void a(PlayerFishEvent event) { + if (event.getState() == State.CAUGHT_FISH) { + ItemStack caught = ((Item) event.getCaught()).getItemStack(); + if (caught.hasItemMeta()) + return; + + PlayerData data = PlayerData.get(event.getPlayer()); + for (FishItemExperienceSource source : getSources()) + if (source.matches(data, caught)) + source.giveExperience(data, caught.getAmount(), event.getHook().getLocation().add(0, 1.0f, 0)); + } + } + }; + } + + @Override + public boolean matchesParameter(PlayerData player, ItemStack obj) { + return obj.getType() == material; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java new file mode 100644 index 00000000..e00ebf48 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java @@ -0,0 +1,50 @@ +package net.Indyuce.mmocore.experience.source; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import io.lumine.mythic.lib.api.event.EntityKillEntityEvent; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +public class KillMobExperienceSource extends SpecificExperienceSource { + public final EntityType type; + + public KillMobExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + + config.validate("type"); + type = EntityType.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void a(EntityKillEntityEvent event) { + Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { + if (event.getTarget().isDead() && event.getEntity() instanceof Player && !event.getEntity().hasMetadata("NPC") + && !event.getTarget().hasMetadata("spawner_spawned")) { + PlayerData data = PlayerData.get((Player) event.getEntity()); + + for (KillMobExperienceSource source : getSources()) + if (source.matches(data, event.getTarget())) + source.giveExperience(data, 1, event.getTarget().getLocation()); + } + }, 2); + } + }; + } + + @Override + public boolean matchesParameter(PlayerData player, Entity obj) { + return obj.getType() == type; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/MineBlockExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/MineBlockExperienceSource.java new file mode 100644 index 00000000..031bfc18 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/MineBlockExperienceSource.java @@ -0,0 +1,66 @@ +package net.Indyuce.mmocore.experience.source; + +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.ItemStack; + +public class MineBlockExperienceSource extends SpecificExperienceSource { + public final Material material; + private final boolean silkTouch; + private final boolean crop; + private final boolean playerPlaced; + + public MineBlockExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + + config.validate("type"); + material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + silkTouch = config.getBoolean("silk-touch", true); + crop = config.getBoolean("crop", false); + playerPlaced = config.getBoolean("player-placed", false); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void a(BlockBreakEvent event) { + if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) + return; + + PlayerData data = PlayerData.get(event.getPlayer()); + + for (MineBlockExperienceSource source : getSources()) { + if (source.silkTouch && hasSilkTouch(event.getPlayer().getInventory().getItemInMainHand())) + continue; + if (source.crop && !MythicLib.plugin.getVersion().getWrapper().isCropFullyGrown(event.getBlock())) + continue; + if ((!source.playerPlaced) && event.getBlock().hasMetadata("player_placed")) + continue; + + if (source.matches(data, event.getBlock().getType())) + source.giveExperience(data, 1, event.getBlock().getLocation()); + } + } + }; + } + + private boolean hasSilkTouch(ItemStack item) { + return item != null && item.hasItemMeta() && item.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH); + } + + @Override + public boolean matchesParameter(PlayerData player, Material obj) { + return material == obj; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/PlaceBlockExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/PlaceBlockExperienceSource.java new file mode 100644 index 00000000..707451dd --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/PlaceBlockExperienceSource.java @@ -0,0 +1,45 @@ +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.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; + +public class PlaceBlockExperienceSource extends SpecificExperienceSource { + public final Material material; + + public PlaceBlockExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + + config.validate("type"); + material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void a(BlockPlaceEvent event) { + if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) + return; + + PlayerData data = PlayerData.get(event.getPlayer()); + for (PlaceBlockExperienceSource source : getSources()) + if (source.matches(data, event.getBlock().getType())) + source.giveExperience(data, 1, event.getBlock().getLocation()); + } + }; + } + + @Override + public boolean matchesParameter(PlayerData player, Material obj) { + return material == obj; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/RepairItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/RepairItemExperienceSource.java new file mode 100644 index 00000000..a1960ebe --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/RepairItemExperienceSource.java @@ -0,0 +1,83 @@ +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.source.type.ExperienceSource; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.AnvilInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; + +public class RepairItemExperienceSource extends ExperienceSource { + private final Material material; + + public RepairItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser); + + /* + * if material is null, the player can repair ANY material in order to + * get experience. + */ + material = config.contains("type") ? Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")) : null; + } + + @Override + public boolean matchesParameter(PlayerData player, ItemStack item) { + return (material == null || item.getType() == material); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void a(InventoryClickEvent event) { + if (event.getInventory() != null && event.getInventory().getType() == InventoryType.ANVIL && event.getSlot() == 2) { + + ItemStack item = event.getCurrentItem(); + PlayerData data = PlayerData.get((Player) event.getWhoClicked()); + + for (RepairItemExperienceSource source : getSources()) + if (source.matches(data, item)) { + + if (!(event.getInventory() instanceof AnvilInventory)) + return; + + if (((AnvilInventory) event.getInventory()).getRepairCost() > ((Player) event.getWhoClicked()).getLevel()) + return; + + /* + * make sure the items can actually be repaired + * before getting the amount of durability repaired + */ + ItemStack old = event.getInventory().getItem(0); + if (old == null || old.getType() == Material.AIR) + return; + if (old.getType().getMaxDurability() < 30 || item.getType().getMaxDurability() < 10) + return; + + if (!MMOCore.plugin.smithingManager.hasExperience(item.getType())) + continue; + + /* + * calculate exp based on amount of durability which + * was repaired, substract damage from old item + * durability. + */ + 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); + } + } + } + }; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/SmeltItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/SmeltItemExperienceSource.java new file mode 100644 index 00000000..d28e6d84 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/SmeltItemExperienceSource.java @@ -0,0 +1,69 @@ +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.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockCookEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Optional; + +public class SmeltItemExperienceSource extends SpecificExperienceSource { + private final Material material; + + public SmeltItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + + config.validate("type"); + material = Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void a(BlockCookEvent event) { + Optional player = getNearestPlayer(event.getBlock().getLocation()); + if (!player.isPresent()) + return; + + ItemStack caught = event.getResult(); + if (caught.hasItemMeta()) + return; + + PlayerData data = PlayerData.get(player.get()); + for (SmeltItemExperienceSource source : getSources()) + if (source.matches(data, caught)) + source.giveExperience(data, 1, event.getBlock().getLocation()); + } + }; + } + + private Optional getNearestPlayer(Location loc) { + final Player[] nearby = loc.getWorld().getPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) < 100) + .toArray(Player[]::new); + Player selected = null; + double lastDist = 100; + for (Player p : nearby) { + double currDist = p.getLocation().distance(loc); + if (currDist < lastDist) { + lastDist = currDist; + selected = p; + } + } + return Optional.ofNullable(selected); + } + + @Override + public boolean matchesParameter(PlayerData player, ItemStack obj) { + return obj.getType() == material; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java new file mode 100644 index 00000000..7a91c7da --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java @@ -0,0 +1,30 @@ +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.manager.profession.ExperienceSourceManager; + +/** + * Atrocious API that really needs rewriting + * + * @author cympe + */ +public abstract class ExperienceSource { + private final ExperienceDispenser dispenser; + + public ExperienceSource(ExperienceDispenser dispenser) { + this.dispenser = dispenser; + } + + public ExperienceDispenser getDispenser() { + return dispenser; + } + + public abstract ExperienceSourceManager newManager(); + + public boolean matches(PlayerData player, T obj) { + return getDispenser().matches(player) && matchesParameter(player, obj); + } + + public abstract boolean matchesParameter(PlayerData player, T obj); +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java new file mode 100644 index 00000000..314028a0 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java @@ -0,0 +1,46 @@ +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.api.player.PlayerData; +import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; +import org.bukkit.Location; +import org.jetbrains.annotations.Nullable; + +public abstract class SpecificExperienceSource extends ExperienceSource { + private final RandomAmount amount; + + /** + * Used to register experience sources with SPECIFIC experience outputs. + * Other experience sources like ENCHANT have their exp output depend on the + * enchanted item. ALCHEMY exp outputs depend on the potion crafted + */ + public SpecificExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser); + + config.validate("amount"); + amount = new RandomAmount(config.getString("amount")); + } + + public RandomAmount getAmount() { + return amount; + } + + public int rollAmount() { + return amount.calculateInt(); + } + + /** + * Used when a player needs to gain experience after performing the action + * corresponding to this exp source + * + * @param player Player gaining the exp + * @param multiplier Used by the CraftItem experience source, multiplies the exp + * earned by a certain factor. When crafting an item, the + * multiplier is equal to the amount of items crafted + * @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); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java b/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java index 6bac95e8..52582271 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java +++ b/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java @@ -2,8 +2,8 @@ package net.Indyuce.mmocore.gui; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Booster; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Booster; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; import net.Indyuce.mmocore.api.player.stats.StatType; diff --git a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java index d0630dd5..02eff450 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java @@ -3,7 +3,7 @@ package net.Indyuce.mmocore.gui; import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.quest.Quest; import net.Indyuce.mmocore.api.util.math.format.DelayFormat; diff --git a/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java b/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java index bc47393c..7f697c80 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java +++ b/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java @@ -4,7 +4,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerExpChangeEvent; -import net.Indyuce.mmocore.api.experience.EXPSource; +import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.api.player.PlayerData; public class RedirectVanillaExp implements Listener { diff --git a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index 5b7296da..bfc2f884 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; -import net.Indyuce.mmocore.api.experience.EXPSource; +import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.api.loot.LootBuilder; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.stats.StatType; diff --git a/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java b/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java index 68835a6f..cd07a80f 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java @@ -9,7 +9,7 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; -public class AttributeManager extends MMOManager { +public class AttributeManager implements MMOManager { private final Map map = new HashMap<>(); public PlayerAttribute get(String id) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java index bcf963b8..17c90715 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java @@ -26,7 +26,7 @@ import net.Indyuce.mmocore.api.player.profess.event.trigger.ClassChosenEventTrig import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger; import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger; -public class ClassManager extends MMOManager { +public class ClassManager implements MMOManager { private final Map map = new HashMap<>(); /* diff --git a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java index 90283e76..2bb3644d 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java @@ -22,7 +22,7 @@ import java.util.*; import java.util.function.Function; import java.util.logging.Level; -public class CustomBlockManager extends MMOManager { +public class CustomBlockManager implements MMOManager { /** * Registered block infos diff --git a/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java b/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java index c8a25660..f781497e 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java @@ -16,7 +16,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.droptable.DropTable; -public class DropTableManager extends MMOManager { +public class DropTableManager implements MMOManager { private final Map map = new HashMap<>(); public void register(DropTable table) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/ExperienceManager.java b/src/main/java/net/Indyuce/mmocore/manager/ExperienceManager.java index e7b71945..9fbed0a9 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ExperienceManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ExperienceManager.java @@ -10,7 +10,7 @@ import java.util.logging.Level; import org.apache.commons.lang.Validate; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.ExpCurve; +import net.Indyuce.mmocore.experience.ExpCurve; public class ExperienceManager { private final Map expCurves = new HashMap<>(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java index 148bf05a..2693dd6e 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Function; +import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; @@ -12,8 +13,7 @@ import com.google.gson.JsonParseException; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.droptable.condition.Condition; import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.api.load.DefaultMMOLoader; import net.Indyuce.mmocore.api.load.MMOLoader; import net.Indyuce.mmocore.api.quest.objective.Objective; @@ -41,8 +41,8 @@ public class MMOLoadManager { return load(Objective.class, config, loader -> loader.loadObjective(config, section)); } - public ExperienceSource loadExperienceSource(MMOLineConfig config, Profession profession) { - return load(ExperienceSource.class, config, loader -> loader.loadExperienceSource(config, profession)); + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { + return load(ExperienceSource.class, config, loader -> loader.loadExperienceSource(config, dispenser)); } public Trigger loadTrigger(MMOLineConfig config) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java index 8b9cdd4f..93df1478 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java @@ -1,7 +1,7 @@ package net.Indyuce.mmocore.manager; -public abstract class MMOManager { - public abstract void reload(); +public interface MMOManager { + void reload(); - public abstract void clear(); + void clear(); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java b/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java index b0da7768..da345e6e 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java @@ -13,7 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.quest.Quest; -public class QuestManager extends MMOManager { +public class QuestManager implements MMOManager { private final Map quests = new LinkedHashMap<>(); public void load(File file) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java index 3fb90d05..a492e387 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java @@ -7,7 +7,7 @@ import org.bukkit.potion.PotionType; import net.Indyuce.mmocore.manager.MMOManager; -public class AlchemyManager extends MMOManager { +public class AlchemyManager implements MMOManager { public double splash, lingering, upgrade, extend; // private Map custom = new HashMap<>(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java index 073a5e1a..8880e0c9 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java @@ -7,7 +7,7 @@ import org.bukkit.enchantments.Enchantment; import net.Indyuce.mmocore.manager.MMOManager; -public class EnchantManager extends MMOManager { +public class EnchantManager implements MMOManager { private final Map base = new HashMap<>(); public void registerBaseExperience(Enchantment enchant, double value) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java deleted file mode 100644 index d90ca5c9..00000000 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.Indyuce.mmocore.manager.profession; - -import java.util.HashSet; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.event.Listener; - -import net.Indyuce.mmocore.MMOCore; - -public abstract class ExperienceManager implements Listener { - private final Set sources = new HashSet<>(); - - public ExperienceManager() { - Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); - } - - public void register(T source) { - sources.add(source); - - getSources(); - } - - public Set getSources() { - return sources; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java new file mode 100644 index 00000000..0744b047 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java @@ -0,0 +1,30 @@ +package net.Indyuce.mmocore.manager.profession; + +import net.Indyuce.mmocore.MMOCore; +import org.bukkit.Bukkit; +import org.bukkit.event.Listener; + +import java.util.HashSet; +import java.util.Set; + +public abstract class ExperienceSourceManager implements Listener { + + /** + * List of all active experience sources + */ + private final Set sources = new HashSet<>(); + + public ExperienceSourceManager() { + Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); + } + + public void registerSource(T source) { + sources.add(source); + + getSources(); + } + + public Set getSources() { + return sources; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java index 47e703d0..e297cc93 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java @@ -19,7 +19,7 @@ import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.manager.MMOManager; import io.lumine.mythic.lib.api.MMOLineConfig; -public class FishingManager extends MMOManager { +public class FishingManager implements MMOManager { private final Set tables = new LinkedHashSet<>(); private static final Random random = new Random(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java index 3bba5b39..e196d335 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java @@ -11,25 +11,25 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.HandlerList; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.experience.Profession; -import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.experience.Profession; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.manager.MMOManager; -public class ProfessionManager extends MMOManager { +public class ProfessionManager implements MMOManager { - /* - * loaded professions. + /** + * Loaded professions. */ private final Map professions = new HashMap<>(); - /* - * saves different experience sources based on experience source type. + /** + * Saves different experience sources based on experience source type. */ - private final Map, ExperienceManager> managers = new HashMap<>(); + private final Map, ExperienceSourceManager> managers = new HashMap<>(); @SuppressWarnings("unchecked") - public ExperienceManager getManager(Class t) { - return (ExperienceManager) managers.get(t); + public ExperienceSourceManager getManager(Class t) { + return (ExperienceSourceManager) managers.get(t); } @SuppressWarnings("unchecked") @@ -38,7 +38,7 @@ public class ProfessionManager extends MMOManager { if (!managers.containsKey(path)) managers.put(path, source.newManager()); - getManager(path).register(source); + getManager(path).registerSource(source); } public void register(Profession profession) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java index a70415c8..7fccef35 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java @@ -7,7 +7,7 @@ import org.bukkit.Material; import net.Indyuce.mmocore.manager.MMOManager; -public class SmithingManager extends MMOManager { +public class SmithingManager implements MMOManager { private final Map base = new HashMap<>(); public void registerBaseExperience(Material material, double value) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java b/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java index d689c014..df9ae3a2 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java @@ -1,7 +1,7 @@ package net.Indyuce.mmocore.manager.social; -import net.Indyuce.mmocore.api.experience.Booster; -import net.Indyuce.mmocore.api.experience.Profession; +import net.Indyuce.mmocore.experience.Booster; +import net.Indyuce.mmocore.experience.Profession; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java b/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java index 8ca0939b..fd111953 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java @@ -15,7 +15,7 @@ import java.util.Set; import java.util.logging.Level; -public class PartyManager extends MMOManager { +public class PartyManager implements MMOManager { private final Set parties = new HashSet<>(); private final Map buffs = new HashMap<>();