Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. package latty.info.lattyskyblock.classes;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Set;
  7. import java.util.UUID;
  8.  
  9. import latty.info.lattyskyblock.DataHandler;
  10. import latty.info.lattyskyblock.LattySkyblock;
  11. import latty.info.lattyskyblock.Utils;
  12.  
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.Location;
  16. import org.bukkit.Material;
  17. import org.bukkit.OfflinePlayer;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.inventory.Inventory;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.inventory.meta.ItemMeta;
  22.  
  23. public class Classes {
  24.  
  25. LattySkyblock plugin;
  26.  
  27. public int maxLevel = 200;
  28. public HashMap<String, Double> experiences = new HashMap<String, Double>();
  29.  
  30.  
  31. public Classes(LattySkyblock plugin) {
  32. this.plugin = plugin;
  33. }
  34.  
  35.  
  36. public double setExperience(Player player, double amount) {
  37.  
  38. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  39. UUID uid = islandOwner.getUniqueId();
  40. double newExp = amount;
  41.  
  42. if(newExp < 0) {
  43. newExp = 0;
  44. } else if (newExp > getExpForLevel(maxLevel)) {
  45. newExp = getExpForLevel(maxLevel);
  46. }
  47.  
  48. DataHandler.setData(uid, "Experience", newExp);
  49. experiences.put(islandOwner.getName(), newExp);
  50.  
  51. return newExp;
  52. }
  53.  
  54.  
  55. public double takeExperience(Player player, double amount) {
  56.  
  57. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  58. UUID uid = islandOwner.getUniqueId();
  59. double newExp = getExperience(player)-amount;
  60.  
  61. if(newExp < 0) {
  62. newExp = 0;
  63. }
  64.  
  65. DataHandler.setData(uid, "Experience", newExp);
  66. experiences.put(islandOwner.getName(), newExp);
  67.  
  68. return newExp;
  69. }
  70.  
  71.  
  72. public double addExperience(Player player, double amount) {
  73.  
  74. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  75. UUID uid = islandOwner.getUniqueId();
  76. double currentExp = getExperience(player);
  77. double newExp = currentExp + amount;
  78.  
  79. if (currentExp >= getExpForLevel(maxLevel)) {
  80. return 0;
  81. }
  82.  
  83. if(newExp > getExpForLevel(maxLevel)){
  84. newExp = getExpForLevel(maxLevel);
  85. }
  86.  
  87. if(getLevelForExp(currentExp) < getLevelForExp(newExp)) {
  88. onLevelUp(player, getLevelForExp(newExp));
  89. }
  90.  
  91. DataHandler.setData(uid, "Experience", newExp);
  92. experiences.put(islandOwner.getName(), newExp);
  93.  
  94. return newExp;
  95. }
  96.  
  97.  
  98. private void onLevelUp(Player player, int newLevel) {
  99.  
  100. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  101. String islandClass = plugin.island.getIslandClass(player);
  102.  
  103. Bukkit.broadcastMessage(Utils.color("&2&l"+islandClass+"&6 "+islandOwner.getName()+"'s &7island has advanced to level&a&l "+newLevel));
  104.  
  105. Set<OfflinePlayer> members = plugin.island.getIslandMembers(player);
  106.  
  107. if(islandOwner.isOnline()) {
  108. Player owner = (Player) islandOwner;
  109. owner.sendMessage(Utils.color("&7Your island has advanced to level &a&l"+newLevel));
  110.  
  111. }
  112.  
  113. if(members != null) {
  114. for(OfflinePlayer member : members) {
  115.  
  116. if(member.isOnline()) {
  117. Player other = (Player) member;
  118.  
  119. other.sendMessage(Utils.color("&7The island has advanced to level &a&l"+newLevel));
  120.  
  121. return;
  122. }
  123.  
  124. }
  125. }
  126.  
  127.  
  128. }
  129.  
  130.  
  131. public double getExperience(Player player) {
  132. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  133.  
  134. return experiences.get(islandOwner.getName());
  135. }
  136.  
  137.  
  138. public int getLevel(Player player) {
  139. return getLevelForExp(getExperience(player));
  140. }
  141.  
  142.  
  143. public double getExpForNextLevel(Player player) {
  144. double nextLevelExp = getExpForLevel(getLevel(player)+1);
  145. return nextLevelExp - getExperience(player);
  146. }
  147.  
  148.  
  149. public double getExpForLevel(int level) {
  150.  
  151. double a = 535 * Math.pow(1.019, level);
  152. double b = 150 * Math.sqrt(level);
  153. double c = 0.1 * (level*level);
  154.  
  155. return Math.floor(a + b - c - 300);
  156. }
  157.  
  158.  
  159. public int getLevelForExp(double experience) {
  160.  
  161. for(int i = 0; i <= (maxLevel); i++) {
  162.  
  163. if(experience >= getExpForLevel(i)) {
  164. continue;
  165. }
  166. return i;
  167. }
  168.  
  169. return 0;
  170. }
  171.  
  172.  
  173. public static void stock(Player player, Inventory inv) {
  174. for(int i = 0; i < strings.length; i++) {
  175. newItem(player, inv, materials[i], integers[i][0], integers[i][1], "&2&l"+strings[i][0], "&7"+strings[i][1], "&7"+strings[i][2], "&7"+strings[i][3]);
  176. }
  177. }
  178.  
  179.  
  180. static Material materials[] = {
  181. Material.DIAMOND_PICKAXE,
  182. Material.MONSTER_EGG,
  183. Material.BREWING_STAND_ITEM,
  184. Material.DIAMOND_HOE,
  185. Material.DIAMOND_AXE
  186. };
  187.  
  188.  
  189. static int[] integers[] = {
  190. {0, 11},
  191. {0, 12},
  192. {0, 13},
  193. {0, 14},
  194. {0, 15},
  195. };
  196.  
  197.  
  198. static String[] strings[] = {
  199. {"Miner", "They focus on using cobblestone generators,", "so they get a bonus on stone dropped", "and can even get ores from it."},
  200. {"Tamer", "They are the experts for all types of creatures.", "They can capture mobs in eggs and breed animals.", ""},
  201. {"Enchanter", "They focus on enchanting and repairing tools.", "Only they can enchant up to level 30 and repair tools.", ""},
  202. {"Farmer", "Their speciality is growing crops, so", "they get a bonus on harvested crops and", "can compost orcanic items to dirt, sand or soul sand."},
  203. {"Lumberjack", "They are the tree experts, so they get a bonus for", "log drops and can chop trees instantly.", ""}
  204. };
  205.  
  206.  
  207. static void newItem(Player player, Inventory inv, Material m, int dataid, int slot, String n, String l, String l2, String l3)
  208. {
  209. ItemStack item = new ItemStack(m);
  210. ItemMeta im = item.getItemMeta();
  211. List<String> lores = new ArrayList<String>();
  212. im.setDisplayName(ChatColor.translateAlternateColorCodes('&', n));
  213. lores.add(ChatColor.translateAlternateColorCodes('&', l));
  214. lores.add(ChatColor.translateAlternateColorCodes('&', l2));
  215. lores.add(ChatColor.translateAlternateColorCodes('&', l3));
  216. item.setDurability((short)dataid);
  217. im.setLore(lores);
  218. item.setItemMeta(im);
  219. inv.setItem(slot, item);
  220. }
  221.  
  222.  
  223. public void apply(Player player, ItemStack clicked) {
  224. String name = clicked.getItemMeta().getDisplayName().substring(4);
  225.  
  226. for(int i = 0; i < strings.length; i++) {
  227. if(name.equalsIgnoreCase(strings[i][0])) {
  228. DataHandler.setData(player.getUniqueId(), "Class", strings[i][0]);
  229. player.sendMessage(Utils.color("&7You have selected &a&lThe "+strings[i][0]+"&7 class."));
  230. if(!plugin.island.hasIsland(player)) {
  231. plugin.islandInv.Inventory(player, "Island Selection");
  232. return;
  233. }
  234. plugin.scoreBoard.addLevels(player);
  235. player.closeInventory();
  236. Location l = new Location(LattySkyblock.getWorld(), plugin.island.checkDouble(player.getUniqueId(), "Island.X"), LattySkyblock.height, plugin.island.checkDouble(player.getUniqueId(), "Island.Z"));
  237. player.teleport(l);
  238. }
  239. }
  240. }
  241.  
  242. public void addPlayer(Player player) {
  243.  
  244. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  245. UUID uid = islandOwner.getUniqueId();
  246.  
  247. experiences.put(islandOwner.getName(), DataHandler.getDouble(uid, "Experience"));
  248.  
  249. }
  250.  
  251. public void clearPlayer(Player player) {
  252.  
  253. OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
  254.  
  255. if(experiences.containsKey(islandOwner.getName())) {
  256.  
  257. Set<OfflinePlayer> members = plugin.island.getIslandMembers(player);
  258. if(members != null) {
  259. for(OfflinePlayer member : members) {
  260.  
  261. if(member.isOnline() && !member.equals(player)) {
  262. return;
  263. }
  264.  
  265. }
  266. }
  267.  
  268. if(islandOwner.isOnline()) {
  269. return;
  270. }
  271.  
  272. experiences.remove(islandOwner.getName());
  273. }
  274.  
  275. if(plugin.scoreBoard.lattyTokens.containsKey(player.getName())) {
  276. plugin.scoreBoard.lattyTokens.remove(player.getName());
  277. }
  278.  
  279. if(plugin.scoreBoard.levels.containsKey(player.getName())) {
  280. plugin.scoreBoard.levels.remove(player.getName());
  281. }
  282.  
  283. if(plugin.scoreBoard.moneyAmounts.containsKey(player.getName())) {
  284. plugin.scoreBoard.moneyAmounts.remove(player.getName());
  285. }
  286.  
  287. }
  288.  
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement