Resource rework. See GitHub wiki for more info

Added an option to disable vanilla eating/sat regen
This commit is contained in:
Indyuce 2020-02-13 23:50:27 +01:00
parent 1d3bed0d1c
commit 2a2a7f7007
15 changed files with 221 additions and 120 deletions

View File

@ -62,6 +62,7 @@ import net.Indyuce.mmocore.listener.PlayerListener;
import net.Indyuce.mmocore.listener.SpellCast; import net.Indyuce.mmocore.listener.SpellCast;
import net.Indyuce.mmocore.listener.WaypointsListener; import net.Indyuce.mmocore.listener.WaypointsListener;
import net.Indyuce.mmocore.listener.option.DeathExperienceLoss; import net.Indyuce.mmocore.listener.option.DeathExperienceLoss;
import net.Indyuce.mmocore.listener.option.DisableRegeneration;
import net.Indyuce.mmocore.listener.option.HealthScale; import net.Indyuce.mmocore.listener.option.HealthScale;
import net.Indyuce.mmocore.listener.option.NoSpawnerEXP; import net.Indyuce.mmocore.listener.option.NoSpawnerEXP;
import net.Indyuce.mmocore.listener.option.VanillaExperienceOverride; import net.Indyuce.mmocore.listener.option.VanillaExperienceOverride;
@ -231,20 +232,13 @@ public class MMOCore extends JavaPlugin {
*/ */
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
for (PlayerData data : PlayerData.getAll()) for (PlayerData player : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead()) { if (player.isOnline() && !player.getPlayer().isDead())
for (PlayerResource resource : PlayerResource.values()) {
data.giveStellium(data.getStats().getStat(StatType.STELLIUM_REGENERATION)); double d = player.getProfess().getHandler(resource).getRegen(player);
if (d > 0)
if (data.canRegen(PlayerResource.HEALTH)) resource.regen(player, d);
data.heal(data.calculateRegen(PlayerResource.HEALTH)); }
if (data.canRegen(PlayerResource.MANA))
data.giveMana(data.calculateRegen(PlayerResource.MANA));
if (data.canRegen(PlayerResource.STAMINA))
data.giveStamina(data.calculateRegen(PlayerResource.STAMINA));
}
} }
}.runTaskTimerAsynchronously(MMOCore.plugin, 100, 20); }.runTaskTimerAsynchronously(MMOCore.plugin, 100, 20);
@ -254,9 +248,9 @@ public class MMOCore extends JavaPlugin {
* produced by people not reading the installation guide... * produced by people not reading the installation guide...
*/ */
if (Bukkit.getPluginManager().getPlugin("MMOItemsMana") != null) { if (Bukkit.getPluginManager().getPlugin("MMOItemsMana") != null) {
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with the Mana & Stamina MMOItems!!!"); getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "MMOCore is not meant to be used with MMOItems ManaAndStamina");
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!"); getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "Please read the installation guide!");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with the Mana & Stamina MMOItems!!!"); Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with MMOItems ManaAndStamina");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!"); Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!");
return; return;
} }
@ -288,6 +282,9 @@ public class MMOCore extends JavaPlugin {
if (getConfig().getBoolean("death-exp-loss.enabled")) if (getConfig().getBoolean("death-exp-loss.enabled"))
Bukkit.getPluginManager().registerEvents(new DeathExperienceLoss(), this); Bukkit.getPluginManager().registerEvents(new DeathExperienceLoss(), this);
if (getConfig().getBoolean("disable-vanilla-regen"))
Bukkit.getPluginManager().registerEvents(new DisableRegeneration(), this);
Bukkit.getPluginManager().registerEvents(new WaypointsListener(), this); Bukkit.getPluginManager().registerEvents(new WaypointsListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this); Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getPluginManager().registerEvents(new GoldPouchesListener(), this); Bukkit.getPluginManager().registerEvents(new GoldPouchesListener(), this);

View File

@ -11,7 +11,6 @@ import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.Indyuce.mmoitems.MMOItems;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
@ -39,7 +38,6 @@ import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.PlayerClass.Subclass; import net.Indyuce.mmocore.api.player.profess.PlayerClass.Subclass;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation; import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.api.player.social.FriendRequest; import net.Indyuce.mmocore.api.player.social.FriendRequest;
import net.Indyuce.mmocore.api.player.social.Party; import net.Indyuce.mmocore.api.player.social.Party;
import net.Indyuce.mmocore.api.player.social.guilds.Guild; import net.Indyuce.mmocore.api.player.social.guilds.Guild;
@ -50,6 +48,7 @@ import net.Indyuce.mmocore.api.skill.Skill.SkillInfo;
import net.Indyuce.mmocore.api.skill.SkillResult; import net.Indyuce.mmocore.api.skill.SkillResult;
import net.Indyuce.mmocore.api.skill.SkillResult.CancelReason; import net.Indyuce.mmocore.api.skill.SkillResult.CancelReason;
import net.Indyuce.mmocore.listener.SpellCast.SkillCasting; import net.Indyuce.mmocore.listener.SpellCast.SkillCasting;
import net.Indyuce.mmoitems.MMOItems;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.MMOLib;
@ -567,14 +566,6 @@ public class PlayerData extends OfflinePlayerData {
return attributes; return attributes;
} }
public boolean canRegen(PlayerResource resource) {
return getProfess().getHandler(resource).isAvailable(this);
}
public double calculateRegen(PlayerResource resource) {
return getProfess().getHandler(resource).getRegen(this);
}
public void setMana(double amount) { public void setMana(double amount) {
mana = Math.max(0, Math.min(amount, getStats().getStat(StatType.MAX_MANA))); mana = Math.max(0, Math.min(amount, getStats().getStat(StatType.MAX_MANA)));
} }

View File

@ -31,6 +31,7 @@ import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.math.formula.LinearValue; import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.math.particle.CastingParticle; import net.Indyuce.mmocore.api.math.particle.CastingParticle;
import net.Indyuce.mmocore.api.player.profess.event.EventTrigger; 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.PlayerResource;
import net.Indyuce.mmocore.api.player.profess.resource.ResourceHandler; import net.Indyuce.mmocore.api.player.profess.resource.ResourceHandler;
import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.player.stats.StatType;
@ -51,9 +52,9 @@ public class PlayerClass {
private final Map<String, SkillInfo> skills = new LinkedHashMap<>(); private final Map<String, SkillInfo> skills = new LinkedHashMap<>();
private final List<Subclass> subclasses = new ArrayList<>(); private final List<Subclass> subclasses = new ArrayList<>();
private Map<String, EventTrigger> eventTriggers = new HashMap<>(); private final Map<PlayerResource, ResourceHandler> resourceHandlers = new HashMap<>();
private final Map<String, EventTrigger> eventTriggers = new HashMap<>();
private final Map<PlayerResource, ResourceHandler> resources = new HashMap<>();
private CastingParticle castParticle = new CastingParticle(Particle.SPELL_INSTANT); private CastingParticle castParticle = new CastingParticle(Particle.SPELL_INSTANT);
/* /*
@ -68,8 +69,8 @@ public class PlayerClass {
name = ChatColor.translateAlternateColorCodes('&', config.getString("display.name")); name = ChatColor.translateAlternateColorCodes('&', config.getString("display.name"));
icon = MMOCoreUtils.readIcon(config.getString("display.item")); icon = MMOCoreUtils.readIcon(config.getString("display.item"));
if(config.contains("display.texture")) { if (config.contains("display.texture")) {
if(icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) { if (icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
ItemMeta meta = icon.getItemMeta(); ItemMeta meta = icon.getItemMeta();
try { try {
Field profileField = meta.getClass().getDeclaredField("profile"); Field profileField = meta.getClass().getDeclaredField("profile");
@ -81,8 +82,7 @@ public class PlayerClass {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not apply playerhead texture: " + exception.getMessage()); MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not apply playerhead texture: " + exception.getMessage());
} }
icon.setItemMeta(meta); icon.setItemMeta(meta);
} } else {
else {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not add player head texture. The item is not a playerhead!"); MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not add player head texture. The item is not a playerhead!");
} }
} }
@ -141,8 +141,6 @@ public class PlayerClass {
for (String key : config.getConfigurationSection("triggers").getKeys(false)) { for (String key : config.getConfigurationSection("triggers").getKeys(false)) {
try { try {
String format = key.toLowerCase().replace("_", "-").replace(" ", "-"); String format = key.toLowerCase().replace("_", "-").replace(" ", "-");
// Validate.isTrue(MMOCore.plugin.classManager.isEventRegistered(format),
// "Could not find trigger event called '" + format + "'");
eventTriggers.put(format, new EventTrigger(format, config.getStringList("triggers." + key))); eventTriggers.put(format, new EventTrigger(format, config.getStringList("triggers." + key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] " + exception.getMessage()); MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] " + exception.getMessage());
@ -150,8 +148,21 @@ public class PlayerClass {
} }
} }
for (PlayerResource resource : PlayerResource.values()) /*
resources.put(resource, new ResourceHandler(this, 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));
}
} }
/* /*
@ -170,7 +181,7 @@ public class PlayerClass {
setOption(ClassOption.DEFAULT, false); setOption(ClassOption.DEFAULT, false);
for (PlayerResource resource : PlayerResource.values()) for (PlayerResource resource : PlayerResource.values())
resources.put(resource, new ResourceHandler(this, resource)); resourceHandlers.put(resource, new ResourceHandler(resource));
} }
public void loadSubclasses(ClassManager manager) { public void loadSubclasses(ClassManager manager) {
@ -193,7 +204,7 @@ public class PlayerClass {
} }
public ResourceHandler getHandler(PlayerResource resource) { public ResourceHandler getHandler(PlayerResource resource) {
return resources.get(resource); return resourceHandlers.get(resource);
} }
public int getMaxLevel() { public int getMaxLevel() {
@ -311,26 +322,13 @@ public class PlayerClass {
*/ */
DISPLAY(true), DISPLAY(true),
/*
* resource regeneration depends on max resource
*/
MISSING_HEALTH_REGEN,
MISSING_MANA_REGEN,
MISSING_STAMINA_REGEN,
/*
* resource regeneration depends on missing resource
*/
MAX_HEALTH_REGEN,
MAX_MANA_REGEN,
MAX_STAMINA_REGEN,
/* /*
* only regen resource when out of combat * only regen resource when out of combat
*/ */
OFF_COMBAT_HEALTH_REGEN, OFF_COMBAT_HEALTH_REGEN,
OFF_COMBAT_MANA_REGEN(true), OFF_COMBAT_MANA_REGEN,
OFF_COMBAT_STAMINA_REGEN; OFF_COMBAT_STAMINA_REGEN,
OFF_COMBAT_STELLIUM_REGEN;
private final boolean def; private final boolean def;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.api.player.profess; package net.Indyuce.mmocore.api.player.profess.resource;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -27,8 +27,8 @@ public class ManaDisplayOptions {
public ManaDisplayOptions(ChatColor color, String name, char barCharacter) { public ManaDisplayOptions(ChatColor color, String name, char barCharacter) {
Validate.notNull(color, "Color cannot be null"); Validate.notNull(color, "Color cannot be null");
Validate.notNull(name, "name cannot be null"); Validate.notNull(name, "Name cannot be null");
Validate.notNull(barCharacter, "barCharacter cannot be null"); Validate.notNull(barCharacter, "Bar character cannot be null");
this.color = color; this.color = color;
this.name = name; this.name = name;

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.api.player.profess.resource; package net.Indyuce.mmocore.api.player.profess.resource;
import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
@ -13,44 +14,41 @@ public enum PlayerResource {
/* /*
* used to handle resource regeneration. * used to handle resource regeneration.
*/ */
HEALTH(StatType.HEALTH_REGENERATION, ClassOption.OFF_COMBAT_HEALTH_REGEN, ClassOption.MAX_HEALTH_REGEN, ClassOption.MISSING_HEALTH_REGEN, (data) -> data.getPlayer().getHealth(), (data) -> data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()), HEALTH(StatType.HEALTH_REGENERATION, ClassOption.OFF_COMBAT_HEALTH_REGEN, (data) -> data.getPlayer().getHealth(), (data) -> data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(), (data, d) -> data.heal(d)),
MANA(StatType.MANA_REGENERATION, ClassOption.OFF_COMBAT_MANA_REGEN, ClassOption.MAX_MANA_REGEN, ClassOption.MISSING_MANA_REGEN, (data) -> data.getMana(), (data) -> data.getStats().getStat(StatType.MAX_MANA)), MANA(StatType.MANA_REGENERATION, ClassOption.OFF_COMBAT_MANA_REGEN, (data) -> data.getMana(), (data) -> data.getStats().getStat(StatType.MAX_MANA), (data, d) -> data.giveMana(d)),
STAMINA(StatType.STAMINA_REGENERATION, ClassOption.OFF_COMBAT_STAMINA_REGEN, ClassOption.MAX_STAMINA_REGEN, ClassOption.MISSING_STAMINA_REGEN, (data) -> data.getStamina(), (data) -> data.getStats().getStat(StatType.MAX_STAMINA)); STAMINA(StatType.STAMINA_REGENERATION, ClassOption.OFF_COMBAT_STAMINA_REGEN, (data) -> data.getStamina(), (data) -> data.getStats().getStat(StatType.MAX_STAMINA), (data, d) -> data.giveStamina(d)),
STELLIUM(StatType.STELLIUM_REGENERATION, ClassOption.OFF_COMBAT_STELLIUM_REGEN, (data) -> data.getStellium(), (data) -> data.getStats().getStat(StatType.MAX_STELLIUM), (data, d) -> data.giveStellium(d));
private final StatType regenStat; private final StatType regenStat;
private final ClassOption offCombatRegen, maxRegen, missingRegen; private final ClassOption offCombatRegen;
private final Function<PlayerData, Double> current, max; private final Function<PlayerData, Double> current, max;
private final BiConsumer<PlayerData, Double> regen;
private PlayerResource(StatType regenStat, ClassOption offCombatRegen, ClassOption maxRegen, ClassOption missingRegen, Function<PlayerData, Double> current, Function<PlayerData, Double> max) { private PlayerResource(StatType regenStat, ClassOption offCombatRegen, Function<PlayerData, Double> current, Function<PlayerData, Double> max, BiConsumer<PlayerData, Double> regen) {
this.regenStat = regenStat; this.regenStat = regenStat;
this.offCombatRegen = offCombatRegen; this.offCombatRegen = offCombatRegen;
this.maxRegen = maxRegen;
this.missingRegen = missingRegen;
this.current = current; this.current = current;
this.max = max; this.max = max;
} this.regen = regen;
public ClassOption getMaxRegen() {
return maxRegen;
}
public ClassOption getMissingRegen() {
return missingRegen;
}
public ClassOption getOffCombatRegen() {
return offCombatRegen;
} }
public StatType getRegenStat() { public StatType getRegenStat() {
return regenStat; return regenStat;
} }
public double getCurrent(PlayerData data) { public ClassOption getOffCombatRegen() {
return current.apply(data); return offCombatRegen;
} }
public double getMax(PlayerData data) { public double getCurrent(PlayerData player) {
return max.apply(data); return current.apply(player);
}
public double getMax(PlayerData player) {
return max.apply(player);
}
public void regen(PlayerData player, double amount) {
regen.accept(player, amount);
} }
} }

View File

@ -1,25 +1,92 @@
package net.Indyuce.mmocore.api.player.profess.resource; package net.Indyuce.mmocore.api.player.profess.resource;
import java.util.function.Function; import java.util.function.BiFunction;
import java.util.function.Predicate;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.math.formula.LinearValue;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
public class ResourceHandler { public class ResourceHandler {
private final Function<PlayerData, Double> regen;
private final Predicate<PlayerData> available;
public ResourceHandler(PlayerClass profess, PlayerResource resource) { /*
available = profess.hasOption(resource.getOffCombatRegen()) ? (data) -> !data.isInCombat() : (data) -> true; * resource regeneration only applies when player is off combat
regen = profess.hasOption(resource.getMaxRegen()) ? (data) -> resource.getMax(data) * data.getStats().getStat(resource.getRegenStat()) / 100 : profess.hasOption(resource.getMissingRegen()) ? (data) -> Math.max(0, resource.getMax(data) - resource.getCurrent(data)) * data.getStats().getStat(resource.getRegenStat()) / 100 : (data) -> data.getStats().getStat(resource.getRegenStat()); */
private final boolean offCombatOnly;
/*
* percentage of scaling which the player regenerates every second
*/
private final LinearValue scalar;
/*
* whether the resource regeneration scales on missing or max resource. if
* TYPE is null, then there is no special regeneration.
*/
private final HandlerType type;
private final PlayerResource resource;
public ResourceHandler(PlayerResource resource) {
this(resource, null, null, false);
} }
public boolean isAvailable(PlayerData data) { public ResourceHandler(PlayerResource resource, ConfigurationSection config) {
return available.test(data); this.resource = resource;
offCombatOnly = config.getBoolean("off-combat");
Validate.isTrue(config.contains("type"), "Could not find resource regen scaling type");
type = HandlerType.valueOf(config.getString("type").toUpperCase());
Validate.notNull(config.getConfigurationSection("value"), "Could not find resource regen value config section");
scalar = new LinearValue(config.getConfigurationSection("value"));
} }
public double getRegen(PlayerData data) { public ResourceHandler(PlayerResource resource, HandlerType type, LinearValue scalar, boolean offCombatOnly) {
return regen.apply(data); this.resource = resource;
this.type = type;
this.scalar = scalar;
this.offCombatOnly = offCombatOnly;
}
/*
* REGENERATION FORMULAS HERE.
*/
public double getRegen(PlayerData player) {
double d = 0;
// base resource regeneration = value of the corresponding regen stat
if (!player.isInCombat() || !player.getProfess().hasOption(resource.getOffCombatRegen()))
d += player.getStats().getStat(resource.getRegenStat());
// extra resource regeneration based on CLASS, scales on LEVEL
if (type != null && (!player.isInCombat() || !offCombatOnly))
d = this.scalar.calculate(player.getLevel()) / 100 * type.getScaling(player, resource);
return d;
}
public enum HandlerType {
/*
* resource regeneration scales on max resource
*/
MAX((player, resource) -> resource.getMax(player)),
/*
* resource regeneration scales on missing resource
*/
MISSING((player, resource) -> resource.getMax(player) - resource.getCurrent(player));
private final BiFunction<PlayerData, PlayerResource, Double> calculation;
private HandlerType(BiFunction<PlayerData, PlayerResource, Double> calculation) {
this.calculation = calculation;
}
public double getScaling(PlayerData player, PlayerResource resource) {
return calculation.apply(player, resource);
}
} }
} }

View File

@ -22,9 +22,10 @@ public class AdminCommandMap extends CommandMap {
addFloor(new PointsCommandMap("attribute", this, (data, points) -> data.setAttributePoints(points), (data, points) -> data.giveAttributePoints(points), (data) -> data.getAttributePoints())); addFloor(new PointsCommandMap("attribute", this, (data, points) -> data.setAttributePoints(points), (data, points) -> data.giveAttributePoints(points), (data) -> data.getAttributePoints()));
addFloor(new PointsCommandMap("attr-realloc", this, (data, points) -> data.setAttributeReallocationPoints(points), (data, points) -> data.giveAttributeReallocationPoints(points), (data) -> data.getAttributeReallocationPoints())); addFloor(new PointsCommandMap("attr-realloc", this, (data, points) -> data.setAttributeReallocationPoints(points), (data, points) -> data.giveAttributeReallocationPoints(points), (data) -> data.getAttributeReallocationPoints()));
addFloor(new ResourcesCommandMap("mana", this, (data, value) -> data.setMana(value), (data, value) -> data.giveMana(value), (data, value) -> data.giveMana(-value), (data) -> data.getMana())); addFloor(new ResourceCommandMap("health", this, (data, value) -> data.getPlayer().setHealth(value), (data, value) -> data.heal(value), (data, value) -> data.heal(-value), (data) -> data.getPlayer().getHealth()));
addFloor(new ResourcesCommandMap("stamina", this, (data, value) -> data.setStamina(value), (data, value) -> data.giveStamina(value), (data, value) -> data.giveStamina(-value), (data) -> data.getStamina())); addFloor(new ResourceCommandMap("mana", this, (data, value) -> data.setMana(value), (data, value) -> data.giveMana(value), (data, value) -> data.giveMana(-value), (data) -> data.getMana()));
addFloor(new ResourcesCommandMap("stellium", this, (data, value) -> data.setStellium(value), (data, value) -> data.giveStellium(value), (data, value) -> data.giveStellium(-value), (data) -> data.getStellium())); addFloor(new ResourceCommandMap("stamina", this, (data, value) -> data.setStamina(value), (data, value) -> data.giveStamina(value), (data, value) -> data.giveStamina(-value), (data) -> data.getStamina()));
addFloor(new ResourceCommandMap("stellium", this, (data, value) -> data.setStellium(value), (data, value) -> data.giveStellium(value), (data, value) -> data.giveStellium(-value), (data) -> data.getStellium()));
} }
@Override @Override

View File

@ -13,11 +13,11 @@ import net.Indyuce.mmocore.command.api.CommandEnd;
import net.Indyuce.mmocore.command.api.CommandMap; import net.Indyuce.mmocore.command.api.CommandMap;
import net.Indyuce.mmocore.command.api.Parameter; import net.Indyuce.mmocore.command.api.Parameter;
public class ResourcesCommandMap extends CommandMap { public class ResourceCommandMap extends CommandMap {
private final String type; private final String type;
private final Function<PlayerData, Double> get; private final Function<PlayerData, Double> get;
public ResourcesCommandMap(String type, CommandMap parent, BiConsumer<PlayerData, Double> set, BiConsumer<PlayerData, Double> give, BiConsumer<PlayerData, Double> take, Function<PlayerData, Double> get) { public ResourceCommandMap(String type, CommandMap parent, BiConsumer<PlayerData, Double> set, BiConsumer<PlayerData, Double> give, BiConsumer<PlayerData, Double> take, Function<PlayerData, Double> get) {
super(parent, "resource-" + type); super(parent, "resource-" + type);
this.type = type; this.type = type;

View File

@ -0,0 +1,18 @@
package net.Indyuce.mmocore.listener.option;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
public class DisableRegeneration implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void a(EntityRegainHealthEvent event) {
if (event.getEntityType() == EntityType.PLAYER)
if (event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN || event.getRegainReason() == RegainReason.EATING)
event.setCancelled(true);
}
}

View File

@ -124,17 +124,14 @@ public class ConfigManager {
} }
} }
private ChatColor getColorOrDefault(String configKey, ChatColor defaultColor) { private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
ChatColor newColor;
try { try {
newColor = ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + configKey).toUpperCase()); return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase());
} }
catch(Exception e) { catch(IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Resource Bar color config '" + configKey + "' is invalid... Using default color."); MMOCore.log(Level.WARNING, "Could not read resource bar color from '" + key + "': using default.");
newColor = defaultColor; return defaultColor;
} }
return newColor;
} }
public DecimalFormat newFormat(String pattern) { public DecimalFormat newFormat(String pattern) {

View File

@ -70,6 +70,11 @@ health-scale:
enabled: true enabled: true
scale: 20 scale: 20
# Disable player health regen due to saturation and eating
# to control health regen via MMOCore resource regen.
# Requires a SERVER reload when changed.
disable-vanilla-regen: false
# Allows to toggle exp hologram from gaining experiences # Allows to toggle exp hologram from gaining experiences
game-indicators: game-indicators:
exp: exp:

View File

@ -5,14 +5,6 @@ options:
default: true default: true
display: false display: false
# Health/mana regen scales on missing health/mana
missing-health-regen: false
missing-mana-regen: false
# Resource regen scales on max mana/health
max-health-regen: false
max-mana-regen: false
# Only regens when out of combat # Only regens when out of combat
off-combat-health-regen: false off-combat-health-regen: false
off-combat-mana-regen: false off-combat-mana-regen: false

View File

@ -44,6 +44,25 @@ cast-particle:
options: options:
off-combat-health-regen: true off-combat-health-regen: true
# Special resource regeneration: (when out of combat),
# players can regen a set % of their maximum mana/missing mana.
# This % can scale with the player level.
# It also works with other player resources: health, stellium and stamina!
resource:
mana:
# Scales with max mana.
type: MAX
# Regen from 3 to 10% of max mana every second
value:
base: 3
per-level: .1
max: 10
# Only regen when out of combat.
off-combat: true
attributes: attributes:
max-health: max-health:
base: 18 base: 18

View File

@ -40,6 +40,25 @@ mana:
cast-particle: cast-particle:
particle: CRIT particle: CRIT
# Special resource regeneration: (when out of combat),
# players can regen a set % of their stamina mana/missing stamina.
# This % can scale with the player level.
# It also works with other player resources: health, stellium and mana!
resource:
stamina:
# Regen scales with missing stamina.
type: MISSING
# Regen from 3 to 10% of missing stamina every second
value:
base: 5
per-level: .2
max: 13
# Only regen when out of combat.
off-combat: true
skills: skills:
WEAKEN: WEAKEN:
level: 3 level: 3

View File

@ -35,7 +35,6 @@ triggers:
options: options:
off-combat-mana-regen: true off-combat-mana-regen: true
off-combat-health-regen: true off-combat-health-regen: true
missing-health-regen: true
cast-particle: cast-particle:
particle: SPELL_WITCH particle: SPELL_WITCH