Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. public class achievementsUtils {
  2.  
  3. private Player user;
  4.  
  5. public achievementsUtils(Player p){
  6. user = p;
  7. }
  8.  
  9. public void unlock(String shortName){
  10. if (check(shortName) == false){
  11. return;
  12. }
  13. if (custom().contains("achievements." + user.getName() + "." + shortName)){
  14. return;
  15. }
  16. credits credits = new credits();
  17. achievements achievements = Main.getInstance().achStore.get(shortName);
  18. if (achievements == null){
  19. return;
  20. }
  21. user.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "+-------------------------------------------+");
  22. user.sendMessage(ChatColor.WHITE + "");
  23. user.sendMessage(ChatColor.AQUA + "Unlocked Achievement: " + achievements.name);
  24. user.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + achievements.description);
  25. user.sendMessage(ChatColor.WHITE + "");
  26. user.sendMessage(ChatColor.GREEN + "+" + achievements.credits + " credits");
  27.  
  28. user.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "+-------------------------------------------+");
  29. credits.setCoins(user,achievements.credits);
  30. File f = new File("plugins/HpWave2", "achievements.yml");
  31. FileConfiguration c = YamlConfiguration.loadConfiguration(f);
  32. c.set("achievements." + user.getName() + "." + achievements.shortName, true);
  33. try {
  34. c.save(f);
  35. } catch (IOException e) {
  36. e.printStackTrace();
  37. }
  38.  
  39. }
  40.  
  41. public boolean check(String shortName){
  42. if (Main.getInstance().achStore.containsKey(shortName)){
  43. return true;
  44. }else{
  45. return false;
  46. }
  47. }
  48.  
  49. public double percent() {
  50. float unlocked = 0.0F;
  51. if (custom().contains("achievements." + user.getName())) {
  52. for (String ach : custom().getConfigurationSection("achievements." + user.getName()).getKeys(false)) {
  53. unlocked += 1.0F;
  54. }
  55. double num = unlocked / Main.getInstance().achStore.size();
  56. num *= 100.0D;
  57. return Math.round(num);
  58. }
  59.  
  60. return 0.0D;
  61. }
  62.  
  63. public void menu(){
  64. int count = 0;
  65. Inventory menu = Bukkit.createInventory(null, 36, "§7Achievements");
  66. for (String key : Main.getInstance().achStore.keySet()) {
  67. if (check(key) == false){
  68. user.sendMessage("nope");
  69. return;
  70. }
  71. achievements achievement = Main.getInstance().achStore.get(key);
  72. ItemStack is;
  73. if (custom().contains("achievements." + user.getName() + "." + achievement.shortName)){
  74. is = new ItemStack(Material.LIME_DYE);
  75. ItemMeta im = is.getItemMeta();
  76. im.setDisplayName(ChatColor.GREEN + "✓ " + achievement.name);
  77. ArrayList<String> lore = new ArrayList<String>();
  78. lore.add("§7" + achievement.description);
  79. im.setLore(lore);
  80. is.setItemMeta(im);
  81.  
  82. menu.setItem(count,is);
  83. count++;
  84. }else{
  85. is = new ItemStack(Material.GRAY_DYE);
  86. ItemMeta im = is.getItemMeta();
  87. im.setDisplayName(ChatColor.RED + "✖ ????");
  88. ArrayList<String> lore = new ArrayList<String>();
  89. lore.add("§7????");
  90. im.setLore(lore);
  91. is.setItemMeta(im);
  92.  
  93. menu.setItem(count,is);
  94. count++;
  95. }
  96. }
  97. user.openInventory(menu);
  98. }
  99.  
  100. public FileConfiguration custom(){
  101. File f = new File("plugins/HpWave2", "achievements.yml");
  102. FileConfiguration c = YamlConfiguration.loadConfiguration(f);
  103. return c;
  104. }
  105. }
  106.  
  107. ============
  108.  
  109. ============
  110.  
  111. public class achievements {
  112.  
  113. String shortName;
  114. String name;
  115. String description;
  116. Integer credits;
  117.  
  118. public achievements(String shortName, String name, String description, Integer Credits){
  119. this.shortName = shortName;
  120. this.name = name;
  121. this.description = description;
  122. this.credits = Credits;
  123. }
  124.  
  125. public void store(){
  126. Main.getInstance().achStore.put(this.shortName,this);
  127. }
  128. }
  129.  
  130. ============
  131.  
  132. ============
  133.  
  134. public class saving {
  135.  
  136. public saving(){}
  137.  
  138. public void load(){
  139. new achievements("welcome","Joining McAmusement", "Enter the gates of McAmusement",50).store();
  140. new achievements("disneyland", "Where it all started", "Visit Disneyland!", 10).store();
  141. new achievements("dca","2nd gate","Visit Disney California Adventure!",10).store();
  142. new achievements("epcot","The future", "Visit Epcot!",10).store();
  143. new achievements("mgm","Lights...Camera...ACTION","Visit MGM studios",10).store();
  144. new achievements("woc","Carousel of Color","That's a lot of water.",20).store();
  145. new achievements("gotg","Mission BREAKOUT", "Hey I can see thanooooooosssssssssssss",20).store();
  146. System.out.println(ChatColor.AQUA + "[HpCore] All achievements have been registered.");
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement