!Exp curve refactor

This commit is contained in:
Indyuce 2020-04-11 12:21:07 +02:00
parent 65ce8db793
commit 9105a8744a
16 changed files with 272 additions and 140 deletions

View File

@ -70,6 +70,7 @@ import net.Indyuce.mmocore.manager.ConfigManager;
import net.Indyuce.mmocore.manager.CustomBlockManager;
import net.Indyuce.mmocore.manager.DropTableManager;
import net.Indyuce.mmocore.manager.EntityManager;
import net.Indyuce.mmocore.manager.ExperienceManager;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.manager.LootableChestManager;
import net.Indyuce.mmocore.manager.MMOLoadManager;
@ -120,6 +121,7 @@ public class MMOCore extends JavaPlugin {
public final QuestManager questManager = new QuestManager();
public final ProfessionManager professionManager = new ProfessionManager();
public final EntityManager entities = new EntityManager();
public final ExperienceManager experience = new ExperienceManager();
/*
* professions
@ -131,7 +133,6 @@ public class MMOCore extends JavaPlugin {
public final MMOLoadManager loadManager = new MMOLoadManager();
public void onLoad() {
plugin = this;
@ -378,6 +379,9 @@ public class MMOCore extends JavaPlugin {
attributeManager.clear();
attributeManager.reload();
// experience must be loaded before professions and classes
experience.reload();
professionManager.clear();
professionManager.reload();

View File

@ -10,15 +10,21 @@ import org.bukkit.potion.PotionType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.player.ExpCurve;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.MMOLineConfig;
public class Profession {
private final String id, name, expCurve;
private final String id, name;
private final ExpCurve expCurve;
/*
* experience given to the main player level whenever he levels up this
* profession
*/
private final LinearValue experience;
/*
* removed when loaded
*/
@ -31,7 +37,9 @@ public class Profession {
this.name = config.getString("name");
Validate.notNull(name, "Could not load name");
expCurve = config.getString("exp-curve", "levels");
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("exp-sources"))
@ -110,10 +118,10 @@ public class Profession {
return name;
}
public String getEXPCurve() {
public ExpCurve getExpCurve() {
return expCurve;
}
public int calculateExperience(int x) {
return (int) experience.calculate(x);
}

View File

@ -0,0 +1,67 @@
package net.Indyuce.mmocore.api.player;
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<Integer> 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);
/*
* read exp curve from a file, one line after the other
*/
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");
}
/*
* can be used by external plugins to register curves and it used by MMOCore
* to create the default exp curve if none is selected
*/
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;
}
/*
* retrieves the experience needed. the level serves as index for the list
* checkup. if the level is higher than the amount of exp inputs, just
* return the last list value
*/
public int getExperience(int level) {
Validate.isTrue(level > 0, "Level must be stricly positive");
return experience.get(Math.min(level, experience.size()) - 1);
}
}

View File

@ -119,7 +119,8 @@ public class PlayerData extends OfflinePlayerData {
j++;
} catch (NullPointerException notFound) {
boundSkills.remove(j);
MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() + " in class " + getProfess().getId() + " while refreshing player data.");
MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() + " in class "
+ getProfess().getId() + " while refreshing player data.");
}
}
@ -191,6 +192,13 @@ public class PlayerData extends OfflinePlayerData {
return skillPoints;
}
/*
* returns level up needed in order to level up
*/
public int getLevelUpExperience() {
return getProfess().getExpCurve().getExperience(getLevel() + 1);
}
// public int getSkillReallocationPoints() {
// return skillReallocationPoints;
// }
@ -223,19 +231,19 @@ public class PlayerData extends OfflinePlayerData {
public void giveLevels(int value) {
int total = 0;
while (value-- > 0)
total += MMOCore.plugin.configManager.getNeededExperience(getLevel() + value + 1, getProfess());
total += getProfess().getExpCurve().getExperience(getLevel() + value + 1);
giveExperience(total);
}
public void setExperience(int value) {
experience = Math.max(0, value);
refreshVanillaExp(MMOCore.plugin.configManager.getNeededExperience(getLevel() + 1, getProfess()));
refreshVanillaExp();
}
public void refreshVanillaExp(float needed) {
public void refreshVanillaExp() {
if (MMOCore.plugin.configManager.overrideVanillaExp) {
player.setLevel(getLevel());
player.setExp((float) experience / needed);
player.setExp((float) experience / (float) getLevelUpExperience());
}
}
@ -346,7 +354,8 @@ public class PlayerData extends OfflinePlayerData {
setLastFriendRequest(System.currentTimeMillis());
FriendRequest request = new FriendRequest(this, target);
new ConfigMessage("friend-request").addPlaceholders("player", getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer());
new ConfigMessage("friend-request").addPlaceholders("player", getPlayer().getName(), "uuid", request.getUniqueId().toString())
.sendAsJSon(target.getPlayer());
MMOCore.plugin.requestManager.registerRequest(request);
}
@ -378,7 +387,9 @@ public class PlayerData extends OfflinePlayerData {
player.playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound(), 1, (float) (t / Math.PI * .015 + .5));
double r = Math.sin((double) t / 100 * Math.PI);
for (double j = 0; j < Math.PI * 2; j += Math.PI / 4)
MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, player.getLocation().add(Math.cos((double) t / 20 + j) * r, (double) t / 50, Math.sin((double) t / 20 + j) * r), 1.25f, Color.PURPLE);
MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE,
player.getLocation().add(Math.cos((double) t / 20 + j) * r, (double) t / 50, Math.sin((double) t / 20 + j) * r), 1.25f,
Color.PURPLE);
}
}.runTaskTimer(MMOCore.plugin, 0, 1);
}
@ -400,7 +411,8 @@ public class PlayerData extends OfflinePlayerData {
// display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms"))
if (loc != null && MMOCore.plugin.hologramSupport != null)
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer());
MMOCore.plugin.hologramSupport.displayIndicator(loc.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;
@ -414,7 +426,7 @@ public class PlayerData extends OfflinePlayerData {
int needed;
boolean check = false;
while (experience >= (needed = MMOCore.plugin.configManager.getNeededExperience(getLevel() + 1, getProfess()))) {
while (experience >= (needed = getLevelUpExperience())) {
if (hasReachedMaxLevel()) {
experience = 0;
@ -434,7 +446,7 @@ public class PlayerData extends OfflinePlayerData {
getStats().getMap().updateAll();
}
refreshVanillaExp(needed);
refreshVanillaExp();
}
public int getExperience() {

View File

@ -49,12 +49,12 @@ public class Professions {
public String toJsonString() {
JsonObject json = new JsonObject();
for (Profession prof : MMOCore.plugin.professionManager.getAll()) {
JsonObject p = new JsonObject();
p.addProperty("exp", getExperience(prof));
p.addProperty("level", getLevel(prof));
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
JsonObject object = new JsonObject();
object.addProperty("exp", getExperience(profession));
object.addProperty("level", getLevel(profession));
json.add(prof.getId(), p);
json.add(profession.getId(), object);
}
return json.toString();
}
@ -90,6 +90,10 @@ public class Professions {
return getExperience(profession.getId());
}
public int getLevelUpExperience(Profession profession) {
return profession.getExpCurve().getExperience(getLevel(profession) + 1);
}
public void setLevel(Profession profession, int value) {
level.put(profession.getId(), value);
}
@ -101,7 +105,7 @@ public class Professions {
public void giveLevels(Profession profession, int value) {
int total = 0, level = getLevel(profession);
while (value-- > 0)
total += MMOCore.plugin.configManager.getNeededExperience(level + value + 1, profession);
total += profession.getExpCurve().getExperience(level + value + 1);
giveExperience(profession, total);
}
@ -116,19 +120,21 @@ public class Professions {
// display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms")) {
if (loc != null && MMOCore.plugin.hologramSupport != null)
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5),
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), playerData.getPlayer());
}
int needed, exp, level;
boolean check = false;
while ((exp = this.exp.get(profession.getId())) >= (needed = MMOCore.plugin.configManager.getNeededExperience((level = getLevel(profession)) + 1, profession))) {
while ((exp = this.exp.get(profession.getId())) >= (needed = profession.getExpCurve().getExperience((level = getLevel(profession)) + 1))) {
this.exp.put(profession.getId(), exp - needed);
this.level.put(profession.getId(), level + 1);
check = true;
playerData.giveExperience((int) profession.getExperience().calculate(level), null);
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(playerData, profession, level + 1));
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + (level + 1), "profession", profession.getName()).send(playerData.getPlayer());
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + (level + 1), "profession", profession.getName())
.send(playerData.getPlayer());
playerData.getPlayer().playSound(playerData.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
}
if (check)
@ -138,6 +144,7 @@ public class Professions {
int chars = (int) ((double) exp / needed * 20);
for (int j = 0; j < 20; j++)
bar += (j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "") + "|";
MMOCore.plugin.configManager.getSimpleMessage("exp-notification", "profession", profession.getName(), "progress", bar, "ratio", MMOCore.plugin.configManager.decimal.format((double) exp / needed * 100)).send(playerData.getPlayer());
MMOCore.plugin.configManager.getSimpleMessage("exp-notification", "profession", profession.getName(), "progress", bar, "ratio",
MMOCore.plugin.configManager.decimal.format((double) exp / needed * 100)).send(playerData.getPlayer());
}
}

View File

@ -26,6 +26,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.AltChar;
import net.Indyuce.mmocore.api.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.load.MMOLoadException;
import net.Indyuce.mmocore.api.player.ExpCurve;
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;
@ -41,12 +42,13 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.version.VersionMaterial;
public class PlayerClass {
private final String name, id, fileName, expCurve;
private final String name, id, fileName;
private final List<String> description = new ArrayList<>(), attrDescription = new ArrayList<>();
private final ItemStack icon;
private final Map<ClassOption, Boolean> options = new HashMap<>();
private final ManaDisplayOptions manaDisplay;
private final int maxLevel, displayOrder;
private final ExpCurve expCurve;
private final Map<StatType, LinearValue> stats = new HashMap<>();
private final Map<String, SkillInfo> skills = new LinkedHashMap<>();
@ -94,12 +96,16 @@ public class PlayerClass {
manaDisplay = new ManaDisplayOptions(config.getConfigurationSection("mana"));
maxLevel = config.getInt("max-level");
displayOrder = config.getInt("display-order");
expCurve = config.getString("exp-curve", "levels");
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)));
stats.put(StatType.valueOf(key.toUpperCase().replace("-", "_")),
new LinearValue(config.getConfigurationSection("attributes." + key)));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load stat info '" + key + "': " + exception.getMessage());
}
@ -156,9 +162,11 @@ public class PlayerClass {
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())));
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());
MMOCore.log(Level.WARNING, "[PlayerClasses:" + id + "] Could not load special resource regen for " + resource.name() + ": "
+ exception.getMessage());
resourceHandlers.put(resource, new ResourceHandler(resource));
}
else
@ -176,7 +184,7 @@ public class PlayerClass {
manaDisplay = new ManaDisplayOptions(ChatColor.BLUE, "Mana", AltChar.listSquare.charAt(0));
maxLevel = 0;
displayOrder = 0;
expCurve = "";
expCurve = ExpCurve.DEFAULT;
this.icon = new ItemStack(material);
setOption(ClassOption.DISPLAY, false);
@ -217,7 +225,7 @@ public class PlayerClass {
return displayOrder;
}
public String getEXPCurve() {
public ExpCurve getExpCurve() {
return expCurve;
}

View File

@ -34,12 +34,17 @@ public class InfoCommandMap extends CommandEnd {
sender.sendMessage(ChatColor.YELLOW + "----------------------------------------------------");
sender.sendMessage(ChatColor.YELLOW + "Class: " + ChatColor.GOLD + playerData.getProfess().getName());
sender.sendMessage(ChatColor.YELLOW + "Level: " + ChatColor.GOLD + playerData.getLevel());
sender.sendMessage(ChatColor.YELLOW + "Experience: " + ChatColor.GOLD + playerData.getExperience() + ChatColor.YELLOW + " / " + ChatColor.GOLD + MMOCore.plugin.configManager.getNeededExperience(playerData.getLevel() + 1, playerData.getProfess()));
sender.sendMessage(ChatColor.YELLOW + "Experience: " + ChatColor.GOLD + playerData.getExperience() + ChatColor.YELLOW + " / " + ChatColor.GOLD
+ playerData.getLevelUpExperience());
sender.sendMessage(ChatColor.YELLOW + "Class Points: " + ChatColor.GOLD + playerData.getClassPoints());
sender.sendMessage(ChatColor.YELLOW + "Quests: " + ChatColor.GOLD + playerData.getQuestData().getFinishedQuests().size() + ChatColor.YELLOW + " / " + ChatColor.GOLD + MMOCore.plugin.questManager.getAll().size());
sender.sendMessage(ChatColor.YELLOW + "Quests: " + ChatColor.GOLD + playerData.getQuestData().getFinishedQuests().size() + ChatColor.YELLOW
+ " / " + ChatColor.GOLD + MMOCore.plugin.questManager.getAll().size());
sender.sendMessage(ChatColor.YELLOW + "----------------------------------------------------");
for (Profession profession : MMOCore.plugin.professionManager.getAll())
sender.sendMessage(ChatColor.YELLOW + profession.getName() + ": Lvl " + ChatColor.GOLD + playerData.getCollectionSkills().getLevel(profession) + ChatColor.YELLOW + " - " + ChatColor.GOLD + playerData.getCollectionSkills().getExperience(profession) + ChatColor.YELLOW + " / " + ChatColor.GOLD + MMOCore.plugin.configManager.getNeededExperience(playerData.getCollectionSkills().getLevel(profession) + 1, profession));
sender.sendMessage(
ChatColor.YELLOW + profession.getName() + ": Lvl " + ChatColor.GOLD + playerData.getCollectionSkills().getLevel(profession)
+ ChatColor.YELLOW + " - " + ChatColor.GOLD + playerData.getCollectionSkills().getExperience(profession)
+ ChatColor.YELLOW + " / " + ChatColor.GOLD + playerData.getCollectionSkills().getLevelUpExperience(profession));
sender.sendMessage(ChatColor.YELLOW + "----------------------------------------------------");
return CommandResult.SUCCESS;
}

View File

@ -1,7 +0,0 @@
package net.Indyuce.mmocore.command.rpg.debug;
import org.bukkit.ChatColor;
public class Debug {
public static final String cmdPrefix = ChatColor.YELLOW + "[" + ChatColor.RED + "DEBUG" + ChatColor.GOLD + "] " + ChatColor.RESET;
}

View File

@ -1,10 +1,13 @@
package net.Indyuce.mmocore.command.rpg.debug;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import net.Indyuce.mmocore.command.api.CommandMap;
public class DebugCommandMap extends CommandMap {
public static final String commandPrefix = ChatColor.YELLOW + "[" + ChatColor.RED + "DEBUG" + ChatColor.GOLD + "] " + ChatColor.RESET;
public DebugCommandMap(CommandMap parent) {
super(parent, "debug");

View File

@ -36,8 +36,8 @@ public class StatValueCommandMap extends CommandEnd {
}
if(args.length > 3 && args[3].equals("true"))
sender.sendMessage(Debug.cmdPrefix + "Stat Value (" + ChatColor.BLUE + stat.name() + ChatColor.WHITE + "): " + ChatColor.GREEN + stat.format(data.getStats().getStat(stat)) + ChatColor.WHITE + " *");
else sender.sendMessage(Debug.cmdPrefix + "Stat Value (" + ChatColor.BLUE + stat.name() + ChatColor.WHITE + "): " + ChatColor.GREEN + data.getStats().getStat(stat));
sender.sendMessage(DebugCommandMap.commandPrefix + "Stat Value (" + ChatColor.BLUE + stat.name() + ChatColor.WHITE + "): " + ChatColor.GREEN + stat.format(data.getStats().getStat(stat)) + ChatColor.WHITE + " *");
else sender.sendMessage(DebugCommandMap.commandPrefix + "Stat Value (" + ChatColor.BLUE + stat.name() + ChatColor.WHITE + "): " + ChatColor.GREEN + data.getStats().getStat(stat));
return CommandResult.SUCCESS;
}

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.AltChar;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.PlayerQuests;
import net.Indyuce.mmocore.api.player.Professions;
@ -40,7 +41,7 @@ public class RPGPlaceholders
else if (identifier.equals("level_percent")) {
PlayerData playerData = PlayerData.get(player);
double current = playerData.getExperience(), next = MMOCore.plugin.configManager.getNeededExperience(playerData.getLevel() + 1, playerData.getProfess());
double current = playerData.getExperience(), next = playerData.getLevelUpExperience();
return MMOCore.plugin.configManager.decimal.format(current / next * 100);
}
@ -55,8 +56,10 @@ public class RPGPlaceholders
else if (identifier.startsWith("profession_percent_")) {
Professions professions = PlayerData.get(player).getCollectionSkills();
String profession = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase();
double current = professions.getExperience(profession), next = MMOCore.plugin.configManager.getNeededExperience(professions.getLevel(profession) + 1, profession);
String name = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase();
Profession profession = MMOCore.plugin.professionManager.get(name);
double current = professions.getExperience(profession),
next = professions.getLevelUpExperience(profession);
return MMOCore.plugin.configManager.decimal.format(current / next * 100);
}
@ -70,7 +73,7 @@ public class RPGPlaceholders
return "" + PlayerData.get(player).getExperience();
else if (identifier.equals("next_level"))
return "" + MMOCore.plugin.configManager.getNeededExperience(PlayerData.get(player).getLevel() + 1, PlayerData.get(player).getProfess());
return "" +PlayerData.get(player).getLevelUpExperience();
else if (identifier.equals("class_points"))
return "" + PlayerData.get(player).getClassPoints();
@ -135,7 +138,10 @@ public class RPGPlaceholders
else if (identifier.equals("quest_progress")) {
PlayerQuests data = PlayerData.get(player).getQuestData();
return data.hasCurrent() ? MMOCore.plugin.configManager.decimal.format((int) (double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100) : "0";
return data.hasCurrent()
? MMOCore.plugin.configManager.decimal
.format((int) (double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100)
: "0";
}
else if (identifier.equals("quest_objective")) {

View File

@ -47,7 +47,7 @@ public class ClassConfirmation extends EditableInventory {
SavedClassInformation info = inv.getPlayerData().getClassInfo(profess);
Placeholders holders = new Placeholders();
int nextLevelExp = MMOCore.plugin.configManager.getNeededExperience(info.getLevel() + 1, profess);
int nextLevelExp = inv.getPlayerData().getLevelUpExperience();
double ratio = (double) info.getExperience() / (double) nextLevelExp;
String bar = "" + ChatColor.BOLD;

View File

@ -79,7 +79,8 @@ public class PlayerStats extends EditableInventory {
Placeholders holders = new Placeholders();
net.Indyuce.mmocore.api.player.stats.PlayerStats stats = inv.getPlayerData().getStats();
double ratio = (double) inv.getPlayerData().getCollectionSkills().getExperience(profession) / MMOCore.plugin.configManager.getNeededExperience(inv.getPlayerData().getCollectionSkills().getLevel(profession) + 1, profession);
double ratio = (double) inv.getPlayerData().getCollectionSkills().getExperience(profession)
/ (double) inv.getPlayerData().getCollectionSkills().getLevelUpExperience(profession);
String bar = "" + ChatColor.BOLD;
int chars = (int) (ratio * 20);
@ -277,7 +278,7 @@ public class PlayerStats extends EditableInventory {
PlayerData data = inv.getPlayerData();
Placeholders holders = new Placeholders();
int nextLevelExp = MMOCore.plugin.configManager.getNeededExperience(data.getLevel() + 1, data.getProfess());
int nextLevelExp = inv.getPlayerData().getLevelUpExperience();
double ratio = (double) data.getExperience() / (double) nextLevelExp;
String bar = "" + ChatColor.BOLD;

View File

@ -1,16 +1,11 @@
package net.Indyuce.mmocore.manager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.bukkit.ChatColor;
@ -20,9 +15,7 @@ import org.bukkit.util.Consumer;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.util.input.AnvilGUI;
import net.Indyuce.mmocore.api.util.input.ChatInput;
import net.Indyuce.mmocore.api.util.input.PlayerInput;
@ -39,7 +32,6 @@ public class ConfigManager {
public final DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols();
public final DecimalFormat decimal = new DecimalFormat("0.#", formatSymbols), decimals = new DecimalFormat("0.##", formatSymbols);
private Map<String, List<Integer>> neededExp = new HashMap<String, List<Integer>>();
private FileConfiguration messages;
private boolean chatInput;
@ -82,7 +74,7 @@ public class ConfigManager {
loadDefaultFile("classes", "rogue.yml");
loadDefaultFile("classes", "warrior.yml");
}
if (!new File(MMOCore.plugin.getDataFolder() + "/expcurves").exists()) {
loadDefaultFile("expcurves", "levels.txt");
loadDefaultFile("expcurves", "mining.txt");
@ -115,37 +107,17 @@ public class ConfigManager {
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
neededExp.clear();
for(File txt : new File(MMOCore.plugin.getDataFolder() + "/expcurves").listFiles()) {
int line = 0;
try {
line++;
//File txt = new File(MMOCore.plugin.getDataFolder(), "levels.txt");
BufferedReader reader = new BufferedReader(new FileReader(txt));
String readLine;
List<Integer> levels = new ArrayList<>();
while ((readLine = reader.readLine()) != null)
levels.add(Integer.valueOf(readLine));
neededExp.put(txt.getName().toLowerCase().replace(".txt", ""), levels);
reader.close();
} catch (IOException | IllegalArgumentException e) {
MMOCore.plugin.getLogger().log(Level.SEVERE, "Could not read line " + line + " from " + txt.getName());
e.printStackTrace();
}
}
}
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
try {
return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase());
}
catch(IllegalArgumentException exception) {
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not read resource bar color from '" + key + "': using default.");
return defaultColor;
}
}
public DecimalFormat newFormat(String pattern) {
return new DecimalFormat(pattern, formatSymbols);
}
@ -176,24 +148,6 @@ public class ConfigManager {
}
}
public int getNeededExperience(int level, PlayerClass clas) {
if(clas == null) return getNeededExperience(level, MMOCore.plugin.classManager.getDefaultClass().getEXPCurve());
return getNeededExperience(level, clas.getEXPCurve());
}
public int getNeededExperience(int level, Profession prof) {
return getNeededExperience(level, prof.getEXPCurve());
}
public int getNeededExperience(int level, String curve) {
List<Integer> expCurve = neededExp.get(curve);
if(expCurve == null) {
MMOCore.log(Level.SEVERE, "Couldn't load EXPCurve: '" + curve + "'. Does it exist?");
return 1;
}
return expCurve.get(level - 1 >= expCurve.size() ? expCurve.size() - 1 : level - 1);
}
public List<String> getMessage(String key) {
return messages.getStringList(key);
}
@ -204,7 +158,7 @@ public class ConfigManager {
format = format.replace("{" + placeholders[j] + "}", placeholders[j + 1]);
return new SimpleMessage(ChatColor.translateAlternateColorCodes('&', format));
}
public class SimpleMessage {
private final String message;

View File

@ -0,0 +1,46 @@
package net.Indyuce.mmocore.manager;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.ExpCurve;
import net.Indyuce.mmoitems.MMOItems;
public class ExperienceManager {
private final Map<String, ExpCurve> expCurves = new HashMap<>();
public boolean hasCurve(String id) {
return expCurves.containsKey(id);
}
public ExpCurve getOrThrow(String id) {
Validate.isTrue(hasCurve(id), "Could not find exp curve with ID '" + id + "'");
return expCurves.get(id);
}
public ExpCurve getCurve(String id) {
return expCurves.get(id);
}
public Collection<ExpCurve> getCurves() {
return expCurves.values();
}
public void reload() {
expCurves.clear();
for (File file : new File(MMOCore.plugin.getDataFolder() + "/expcurves").listFiles())
try {
ExpCurve curve = new ExpCurve(file);
expCurves.put(curve.getId(), curve);
} catch (IllegalArgumentException | IOException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load exp curve '" + file.getName() + "': " + exception.getMessage());
}
}
}

View File

@ -11,15 +11,15 @@ import org.bukkit.configuration.file.FileConfiguration;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.player.social.guilds.Guild;
public abstract class GuildDataManager {
public abstract class GuildDataManager {
protected final Map<String, Guild> guilds = new HashMap<>();
public Guild newRegisteredGuild(UUID owner, String name, String tag) {
Guild guild = new Guild(owner, name, tag);
registerGuild(guild);
return guild;
}
public void registerGuild(Guild guild) {
guilds.put(guild.getId(), guild);
}
@ -31,85 +31,103 @@ public abstract class GuildDataManager {
public boolean isRegistered(String tag) {
return guilds.containsKey(tag);
}
public void unregisterGuild(Guild guild) {
guild.getMembers().forEach(member -> guild.removeMember(member, true));
guild.getMembers().clear();
// guild.getMembers().clear();
guilds.remove(guild.getId());
delete(guild);
}
public Guild stillInGuild(UUID uuid, String id) {
Guild guild = getGuild(id);
if(guild != null && guild.getMembers().has(uuid))
if (guild != null && guild.getMembers().has(uuid))
return guild;
return null;
}
public Guild getGuild(String guild)
{ return guilds.get(guild); }
public Collection<Guild> getAll()
{ return guilds.values(); }
public Guild getGuild(String guild) {
return guilds.get(guild);
}
public Collection<Guild> getAll() {
return guilds.values();
}
public void reload() {
for(Guild guild : guilds.values())
for (Guild guild : guilds.values())
save(guild);
guilds.clear();
load();
config = new GuildConfiguration();
}
public abstract void save(Guild guild);
public abstract void load();
public abstract void delete(Guild guild);
//Shitty code for loading config values for guilds.
// Shitty code for loading config values for guilds.
private GuildConfiguration config;
public GuildConfiguration getConfig() {
if(config == null)
if (config == null)
config = new GuildConfiguration();
return config;
}
public class GuildConfiguration {
private final String prefix;
private final boolean uppercaseTags;
private final NamingRules tagRules, nameRules;
public GuildConfiguration() {
FileConfiguration config = new ConfigFile("guilds").getConfig();
this.prefix = config.getString("chat-prefix", "*");
this.uppercaseTags = config.getBoolean("uppercase-tags", true);
this.tagRules = new NamingRules(config.getConfigurationSection("rules.tag"));
this.nameRules = new NamingRules(config.getConfigurationSection("rules.name"));
}
public String getPrefix()
{ return prefix; }
public boolean shouldUppercaseTags()
{ return uppercaseTags; }
public NamingRules getTagRules()
{ return tagRules; }
public NamingRules getNameRules()
{ return nameRules; }
public String getPrefix() {
return prefix;
}
public boolean shouldUppercaseTags() {
return uppercaseTags;
}
public NamingRules getTagRules() {
return tagRules;
}
public NamingRules getNameRules() {
return nameRules;
}
public class NamingRules {
private final String regex;
private final int min, max;
public NamingRules(ConfigurationSection config) {
regex = config.getString("matches", "[a-zA-Z-_!?]+");
min = config.getInt("min-length", 3);
max = config.getInt("max-length", 5);
}
public String getRegex()
{ return regex; }
public int getMin()
{ return min; }
public int getMax()
{ return max; }
public String getRegex() {
return regex;
}
public int getMin() {
return min;
}
public int getMax() {
return max;
}
}
}
}