Added new options to disable profession exp holos

This commit is contained in:
Indyuce 2021-01-02 00:22:47 +01:00
parent 4472198da3
commit 568d6da795
9 changed files with 128 additions and 60 deletions

View File

@ -1,5 +1,7 @@
package net.Indyuce.mmocore.api.event;
import javax.annotation.Nullable;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -21,7 +23,7 @@ public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancel
this(player, null, experience, source);
}
public PlayerExperienceGainEvent(PlayerData player, Profession profession, int experience, EXPSource source) {
public PlayerExperienceGainEvent(PlayerData player, @Nullable Profession profession, int experience, EXPSource source) {
super(player);
this.profession = profession;
@ -58,7 +60,7 @@ public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancel
public EXPSource getSource() {
return source;
}
@Override
public HandlerList getHandlers() {
return handlers;

View File

@ -4,8 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.Indyuce.mmocore.manager.SoundManager;
import net.mmogroup.mmolib.MMOLib;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -22,6 +22,8 @@ import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.manager.SoundManager;
import net.mmogroup.mmolib.MMOLib;
public class PlayerProfessions {
private final Map<String, Integer> exp = new HashMap<>();
@ -121,14 +123,14 @@ public class PlayerProfessions {
}
public void giveExperience(Profession profession, int value, EXPSource source) {
giveExperience(profession, value, null, source);
giveExperience(profession, value, source, null);
}
public boolean hasReachedMaxLevel(Profession profession) {
return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel();
}
public void giveExperience(Profession profession, int value, Location loc, EXPSource source) {
public void giveExperience(Profession profession, int value, EXPSource source, @Nullable Location hologramLocation) {
if (hasReachedMaxLevel(profession)) {
setExperience(profession, 0);
return;
@ -137,10 +139,9 @@ public class PlayerProfessions {
value = MMOCore.plugin.boosterManager.calculateExp(profession, value);
// display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms") && playerData.isOnline())
if (loc != null && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());
if (hologramLocation != null && playerData.isOnline() && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(hologramLocation.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());
PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source);
Bukkit.getPluginManager().callEvent(event);

View File

@ -1,5 +1,7 @@
package net.Indyuce.mmocore.api.experience;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
@ -19,6 +21,7 @@ public class Profession extends PostLoadObject {
private final String id, name;
private final ExpCurve expCurve;
private final int maxLevel;
private final Map<ProfessionOption, Boolean> options = new HashMap<>();
/*
* experience given to the main player level whenever he levels up this
@ -34,21 +37,29 @@ public class Profession extends PostLoadObject {
Validate.notNull(name, "Could not load name");
expCurve = config.contains("exp-curve")
? MMOCore.plugin.experience.getOrThrow(
config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
? 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));
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());
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage());
}
}
@ -67,16 +78,14 @@ public class Profession extends PostLoadObject {
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.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));
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);
}
@ -85,10 +94,8 @@ public class Profession extends PostLoadObject {
if (config.contains("base-enchant-exp"))
for (String key : config.getConfigurationSection("base-enchant-exp").getKeys(false))
try {
Enchantment enchant = MMOLib.plugin.getVersion().getWrapper()
.getEnchantmentFromString(key.toLowerCase().replace("-", "_"));
MMOCore.plugin.enchantManager.registerBaseExperience(enchant,
config.getDouble("base-enchant-exp." + key));
Enchantment enchant = MMOLib.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);
}
@ -97,8 +104,7 @@ public class Profession extends PostLoadObject {
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));
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);
}
@ -116,6 +122,10 @@ public class Profession extends PostLoadObject {
// }
}
public boolean getOption(ProfessionOption option) {
return options.getOrDefault(option, option.getDefault());
}
public String getId() {
return id;
}
@ -143,4 +153,22 @@ public class Profession extends PostLoadObject {
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;
}
}
}

View File

@ -1,13 +1,22 @@
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<T> {
private final Profession profession;
private PlayerClass profess;
@ -46,13 +55,26 @@ public abstract class ExperienceSource<T> {
public abstract boolean matches(PlayerData player, T obj);
public void giveExperience(PlayerData player, int amount, Location location) {
if (hasProfession())
player.getCollectionSkills().giveExperience(profession, amount, location == null ? getPlayerLocation(player) : location, EXPSource.SOURCE);
else
player.giveExperience(amount, location == null ? getPlayerLocation(player) : location, EXPSource.SOURCE);
/**
* 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;
}

View File

@ -10,6 +10,8 @@ import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
@ -453,20 +455,29 @@ public class PlayerData extends OfflinePlayerData {
}
public void giveExperience(int value, EXPSource source) {
giveExperience(value, null, source);
giveExperience(value, source, null);
}
public void giveExperience(int value, Location loc, EXPSource source) {
/**
* Called when giving experience to a player
*
* @param value Experience to give the player
* @param source How the player earned experience
* @param loc 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) {
if (hasReachedMaxLevel()) {
setExperience(0);
return;
}
// display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms") && isOnline())
if (loc != null && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer());
/*
* Handle experience hologram
*/
if (hologramLocation != null && isOnline() && MMOCore.plugin.hasHolograms())
MMOCore.plugin.hologramSupport.displayIndicator(hologramLocation.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer());
value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;
@ -755,8 +766,8 @@ public class PlayerData extends OfflinePlayerData {
return new SkillResult(this, skill, CancelReason.OTHER);
/*
* skill, mana stamina aand cooldown requirements are all calculated in the
* SkillResult instances. this cast(SkillResult) method only applies
* skill, mana stamina aand cooldown requirements are all calculated in
* the SkillResult instances. this cast(SkillResult) method only applies
* cooldown, reduces mana and/or stamina and send messages
*/
SkillResult cast = skill.getSkill().whenCast(this, skill);

View File

@ -2,7 +2,6 @@ package net.Indyuce.mmocore.command.rpg.admin;
import java.util.function.BiConsumer;
import net.Indyuce.mmocore.command.CommandVerbose;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -13,6 +12,7 @@ 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.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import net.mmogroup.mmolib.command.api.CommandTreeNode;
import net.mmogroup.mmolib.command.api.Parameter;
@ -22,7 +22,8 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
super(parent, "exp");
addChild(new ActionCommandTreeNode(this, "set", PlayerData::setExperience, PlayerProfessions::setExperience));
addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, data.getPlayer().getLocation(), EXPSource.COMMAND), (professions, profession, value) -> professions.giveExperience(profession, value, professions.getPlayerData().getPlayer().getLocation(), EXPSource.COMMAND)));
addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, EXPSource.COMMAND), (professions, profession,
value) -> professions.giveExperience(profession, value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
}
public static class ActionCommandTreeNode extends CommandTreeNode {
@ -63,8 +64,8 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
PlayerData data = PlayerData.get(player);
if (args[4].equalsIgnoreCase("main")) {
main.accept(data, amount);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName()
+ ChatColor.YELLOW + " now has " + ChatColor.GOLD + data.getExperience() + ChatColor.YELLOW + " EXP.");
CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName() + ChatColor.YELLOW
+ " now has " + ChatColor.GOLD + data.getExperience() + ChatColor.YELLOW + " EXP.");
return CommandResult.SUCCESS;
}
@ -76,8 +77,9 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
Profession profession = MMOCore.plugin.professionManager.get(format);
this.profession.accept(data.getCollectionSkills(), profession, amount);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has "
+ ChatColor.GOLD + data.getCollectionSkills().getExperience(profession) + ChatColor.YELLOW + " EXP in " + profession.getName() + ".");
CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE,
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD
+ data.getCollectionSkills().getExperience(profession) + ChatColor.YELLOW + " EXP in " + profession.getName() + ".");
return CommandResult.SUCCESS;
}
}

View File

@ -6,6 +6,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class HologramSupport {
/**
* Displays a message using a hologram
*

View File

@ -5,7 +5,6 @@ import java.util.Random;
import java.util.Set;
import java.util.UUID;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -31,6 +30,7 @@ import net.Indyuce.mmocore.api.experience.EXPSource;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable;
import net.mmogroup.mmolib.version.VersionSound;
@ -47,10 +47,9 @@ public class FishingListener implements Listener {
if (event.getState() == State.BITE && !fishing.contains(player.getUniqueId()) && !player.hasMetadata("NPC")) {
/*
* checks for drop tables. if no drop table, just plain vanilla
* Checks for drop tables. If no drop table, just plain vanilla
* fishing OTHERWISE initialize fishing, register other listener.
*/
FishingDropTable table = MMOCore.plugin.fishingManager.calculateDropTable(player);
if (table == null)
return;
@ -127,7 +126,7 @@ public class FishingListener implements Listener {
&& (event.getState() == State.CAUGHT_FISH || event.getState() == State.FAILED_ATTEMPT || event.getState() == State.REEL_IN)) {
/*
* lose the catch if the current fish is gone!
* Lose the catch if the current fish is gone!
*/
event.setCancelled(true);
if (isTimedOut()) {
@ -140,19 +139,20 @@ public class FishingListener implements Listener {
criticalFish();
/*
* checks for enough pulls. if not, return and wait for next
* Checks for enough pulls. if not, return and wait for next
* fish event.
*/
if (!pull())
return;
/*
* successfully pulls the fish
* Successfully pulls the fish
*/
close();
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
MMOCoreUtils.decreaseDurability(player, (mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
MMOCoreUtils.decreaseDurability(player,
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
if (!isCrit() && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
@ -187,8 +187,8 @@ public class FishingListener implements Listener {
4 * (random.nextDouble() - .5), .05);
if (MMOCore.plugin.professionManager.has("fishing"))
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, location,
EXPSource.FISHING);
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, EXPSource.FISHING,
location);
}
}
}

View File

@ -8,7 +8,7 @@
# a Spigot Plugin by Team Requiem
# DO NOT TOUCH
config-version: 5
config-version: 6
# Auto-Save feature automatically saves playerdata
# (class, level, etc.) and guild data
@ -113,6 +113,10 @@ vanilla-exp-redirection:
# Requires a SERVER reload when changed.
override-vanilla-exp: true
# If main class experience holograms should be displayed
# whenever a player earns main class exp
display-main-class-exp-holograms: true
# Requires a SERVER reload when changed.
death-exp-loss:
enabled: false
@ -120,9 +124,6 @@ death-exp-loss:
# Percentage of current EXP you lose when dying.
percent: 30
# Allows to toggle exp hologram from gaining experience
display-exp-holograms: true
# Put the "value" of the action you want.
# If the value is invalid or empty it will
# default to the vanilla minecraft action.