Advertisement
Guest User

Untitled

a guest
May 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. package mystic.core.attributes;
  2.  
  3. import java.math.RoundingMode;
  4. import java.text.DecimalFormat;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7.  
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10.  
  11. import mystic.core.EnumHandler.Config;
  12. import mystic.core.user.User;
  13.  
  14. public abstract class Attributes {
  15.  
  16. protected int LEVEL = 1;
  17. protected int EXP = 0;
  18. protected Map<Integer, Integer> LEVEL_EXP = new HashMap<>();
  19.  
  20. public abstract void save();
  21.  
  22. public abstract void init();
  23.  
  24. public abstract StringBuilder getInfo();
  25.  
  26. public abstract int getMaxLevel();
  27.  
  28. public int getEXP() {
  29. return EXP;
  30. }
  31.  
  32. public void setEXP(int exp) {
  33. EXP = exp;
  34. }
  35.  
  36. public void addExp(int exp) {
  37. EXP += exp;
  38. }
  39.  
  40. public int getLevel() {
  41. return LEVEL;
  42. }
  43.  
  44. public void setLevel(int lvl) {
  45. LEVEL = lvl;
  46. if (LEVEL > getMaxLevel())
  47. LEVEL = getMaxLevel();
  48. }
  49.  
  50. public void addLevel(int lvl) {
  51. LEVEL += lvl;
  52. if (LEVEL > getMaxLevel())
  53. LEVEL = getMaxLevel();
  54. }
  55.  
  56. public boolean checkLevelUp() {
  57. if (EXP >= LEVEL_EXP.get(LEVEL + 1)) {
  58. EXP = 0;
  59. addLevel(1);
  60. return true;
  61. }
  62. return false;
  63. }
  64.  
  65. public int getLevelExp(int level) {
  66. return LEVEL_EXP.get(level);
  67. }
  68.  
  69. public abstract void applyEffect(User user, boolean firstTime);
  70.  
  71. public Attributes() {
  72. }
  73.  
  74. public String proggres() {
  75. char BAR_CHAR = ':';
  76. StringBuilder text = new StringBuilder();
  77. int next = getLevelExp(LEVEL + 1);
  78. int now = EXP;
  79. if (now > next) {
  80. now = next;
  81. }
  82. text.append(ChatColor.GREEN + "Current level: " + LEVEL + "\n");
  83. text.append(ChatColor.GREEN + "Proggres: ");
  84. int fullDisplay = 30;
  85. int timeIncompleted = (int) (fullDisplay * (Math.min(now, next) / ((double) next)));
  86. int timeCompleted = fullDisplay - timeIncompleted;
  87. text.append(ChatColor.GREEN);
  88. for (int i = 0; i < timeIncompleted; i++) {
  89. text.append(BAR_CHAR);
  90. }
  91. text.append(ChatColor.RED);
  92. for (int i = 0; i < timeCompleted; i++) {
  93. text.append(BAR_CHAR);
  94. }
  95. text.append(ChatColor.RESET);
  96. text.append(' ');
  97. double d = (((now) / (double) next) * 100);
  98. DecimalFormat df = new DecimalFormat("#.#");
  99. df.setRoundingMode(RoundingMode.CEILING);
  100. String kd = df.format(d) + "%";
  101. text.append(kd);
  102. return text.toString();
  103. }
  104.  
  105. public FileConfiguration getConfig() {
  106. return Config.ATTRIBUTES.getConfig();
  107. }
  108.  
  109. public void saveConfig() {
  110. Config.ATTRIBUTES.save();
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement