Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mystic.core.attributes;
- import java.math.RoundingMode;
- import java.text.DecimalFormat;
- import java.util.HashMap;
- import java.util.Map;
- import org.bukkit.ChatColor;
- import org.bukkit.configuration.file.FileConfiguration;
- import mystic.core.EnumHandler.Config;
- import mystic.core.user.User;
- public abstract class Attributes {
- protected int LEVEL = 1;
- protected int EXP = 0;
- protected Map<Integer, Integer> LEVEL_EXP = new HashMap<>();
- public abstract void save();
- public abstract void init();
- public abstract StringBuilder getInfo();
- public abstract int getMaxLevel();
- public int getEXP() {
- return EXP;
- }
- public void setEXP(int exp) {
- EXP = exp;
- }
- public void addExp(int exp) {
- EXP += exp;
- }
- public int getLevel() {
- return LEVEL;
- }
- public void setLevel(int lvl) {
- LEVEL = lvl;
- if (LEVEL > getMaxLevel())
- LEVEL = getMaxLevel();
- }
- public void addLevel(int lvl) {
- LEVEL += lvl;
- if (LEVEL > getMaxLevel())
- LEVEL = getMaxLevel();
- }
- public boolean checkLevelUp() {
- if (EXP >= LEVEL_EXP.get(LEVEL + 1)) {
- EXP = 0;
- addLevel(1);
- return true;
- }
- return false;
- }
- public int getLevelExp(int level) {
- return LEVEL_EXP.get(level);
- }
- public abstract void applyEffect(User user, boolean firstTime);
- public Attributes() {
- }
- public String proggres() {
- char BAR_CHAR = ':';
- StringBuilder text = new StringBuilder();
- int next = getLevelExp(LEVEL + 1);
- int now = EXP;
- if (now > next) {
- now = next;
- }
- text.append(ChatColor.GREEN + "Current level: " + LEVEL + "\n");
- text.append(ChatColor.GREEN + "Proggres: ");
- int fullDisplay = 30;
- int timeIncompleted = (int) (fullDisplay * (Math.min(now, next) / ((double) next)));
- int timeCompleted = fullDisplay - timeIncompleted;
- text.append(ChatColor.GREEN);
- for (int i = 0; i < timeIncompleted; i++) {
- text.append(BAR_CHAR);
- }
- text.append(ChatColor.RED);
- for (int i = 0; i < timeCompleted; i++) {
- text.append(BAR_CHAR);
- }
- text.append(ChatColor.RESET);
- text.append(' ');
- double d = (((now) / (double) next) * 100);
- DecimalFormat df = new DecimalFormat("#.#");
- df.setRoundingMode(RoundingMode.CEILING);
- String kd = df.format(d) + "%";
- text.append(kd);
- return text.toString();
- }
- public FileConfiguration getConfig() {
- return Config.ATTRIBUTES.getConfig();
- }
- public void saveConfig() {
- Config.ATTRIBUTES.save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement