Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package latty.info.lattyskyblock.classes;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Set;
- import java.util.UUID;
- import latty.info.lattyskyblock.DataHandler;
- import latty.info.lattyskyblock.LattySkyblock;
- import latty.info.lattyskyblock.Utils;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- public class Classes {
- LattySkyblock plugin;
- public int maxLevel = 200;
- public HashMap<String, Double> experiences = new HashMap<String, Double>();
- public Classes(LattySkyblock plugin) {
- this.plugin = plugin;
- }
- public double setExperience(Player player, double amount) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- UUID uid = islandOwner.getUniqueId();
- double newExp = amount;
- if(newExp < 0) {
- newExp = 0;
- } else if (newExp > getExpForLevel(maxLevel)) {
- newExp = getExpForLevel(maxLevel);
- }
- DataHandler.setData(uid, "Experience", newExp);
- experiences.put(islandOwner.getName(), newExp);
- return newExp;
- }
- public double takeExperience(Player player, double amount) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- UUID uid = islandOwner.getUniqueId();
- double newExp = getExperience(player)-amount;
- if(newExp < 0) {
- newExp = 0;
- }
- DataHandler.setData(uid, "Experience", newExp);
- experiences.put(islandOwner.getName(), newExp);
- return newExp;
- }
- public double addExperience(Player player, double amount) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- UUID uid = islandOwner.getUniqueId();
- double currentExp = getExperience(player);
- double newExp = currentExp + amount;
- if (currentExp >= getExpForLevel(maxLevel)) {
- return 0;
- }
- if(newExp > getExpForLevel(maxLevel)){
- newExp = getExpForLevel(maxLevel);
- }
- if(getLevelForExp(currentExp) < getLevelForExp(newExp)) {
- onLevelUp(player, getLevelForExp(newExp));
- }
- DataHandler.setData(uid, "Experience", newExp);
- experiences.put(islandOwner.getName(), newExp);
- return newExp;
- }
- private void onLevelUp(Player player, int newLevel) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- String islandClass = plugin.island.getIslandClass(player);
- Bukkit.broadcastMessage(Utils.color("&2&l"+islandClass+"&6 "+islandOwner.getName()+"'s &7island has advanced to level&a&l "+newLevel));
- Set<OfflinePlayer> members = plugin.island.getIslandMembers(player);
- if(islandOwner.isOnline()) {
- Player owner = (Player) islandOwner;
- owner.sendMessage(Utils.color("&7Your island has advanced to level &a&l"+newLevel));
- }
- if(members != null) {
- for(OfflinePlayer member : members) {
- if(member.isOnline()) {
- Player other = (Player) member;
- other.sendMessage(Utils.color("&7The island has advanced to level &a&l"+newLevel));
- return;
- }
- }
- }
- }
- public double getExperience(Player player) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- return experiences.get(islandOwner.getName());
- }
- public int getLevel(Player player) {
- return getLevelForExp(getExperience(player));
- }
- public double getExpForNextLevel(Player player) {
- double nextLevelExp = getExpForLevel(getLevel(player)+1);
- return nextLevelExp - getExperience(player);
- }
- public double getExpForLevel(int level) {
- double a = 535 * Math.pow(1.019, level);
- double b = 150 * Math.sqrt(level);
- double c = 0.1 * (level*level);
- return Math.floor(a + b - c - 300);
- }
- public int getLevelForExp(double experience) {
- for(int i = 0; i <= (maxLevel); i++) {
- if(experience >= getExpForLevel(i)) {
- continue;
- }
- return i;
- }
- return 0;
- }
- public static void stock(Player player, Inventory inv) {
- for(int i = 0; i < strings.length; i++) {
- 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]);
- }
- }
- static Material materials[] = {
- Material.DIAMOND_PICKAXE,
- Material.MONSTER_EGG,
- Material.BREWING_STAND_ITEM,
- Material.DIAMOND_HOE,
- Material.DIAMOND_AXE
- };
- static int[] integers[] = {
- {0, 11},
- {0, 12},
- {0, 13},
- {0, 14},
- {0, 15},
- };
- static String[] strings[] = {
- {"Miner", "They focus on using cobblestone generators,", "so they get a bonus on stone dropped", "and can even get ores from it."},
- {"Tamer", "They are the experts for all types of creatures.", "They can capture mobs in eggs and breed animals.", ""},
- {"Enchanter", "They focus on enchanting and repairing tools.", "Only they can enchant up to level 30 and repair tools.", ""},
- {"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."},
- {"Lumberjack", "They are the tree experts, so they get a bonus for", "log drops and can chop trees instantly.", ""}
- };
- static void newItem(Player player, Inventory inv, Material m, int dataid, int slot, String n, String l, String l2, String l3)
- {
- ItemStack item = new ItemStack(m);
- ItemMeta im = item.getItemMeta();
- List<String> lores = new ArrayList<String>();
- im.setDisplayName(ChatColor.translateAlternateColorCodes('&', n));
- lores.add(ChatColor.translateAlternateColorCodes('&', l));
- lores.add(ChatColor.translateAlternateColorCodes('&', l2));
- lores.add(ChatColor.translateAlternateColorCodes('&', l3));
- item.setDurability((short)dataid);
- im.setLore(lores);
- item.setItemMeta(im);
- inv.setItem(slot, item);
- }
- public void apply(Player player, ItemStack clicked) {
- String name = clicked.getItemMeta().getDisplayName().substring(4);
- for(int i = 0; i < strings.length; i++) {
- if(name.equalsIgnoreCase(strings[i][0])) {
- DataHandler.setData(player.getUniqueId(), "Class", strings[i][0]);
- player.sendMessage(Utils.color("&7You have selected &a&lThe "+strings[i][0]+"&7 class."));
- if(!plugin.island.hasIsland(player)) {
- plugin.islandInv.Inventory(player, "Island Selection");
- return;
- }
- plugin.scoreBoard.addLevels(player);
- player.closeInventory();
- Location l = new Location(LattySkyblock.getWorld(), plugin.island.checkDouble(player.getUniqueId(), "Island.X"), LattySkyblock.height, plugin.island.checkDouble(player.getUniqueId(), "Island.Z"));
- player.teleport(l);
- }
- }
- }
- public void addPlayer(Player player) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- UUID uid = islandOwner.getUniqueId();
- experiences.put(islandOwner.getName(), DataHandler.getDouble(uid, "Experience"));
- }
- public void clearPlayer(Player player) {
- OfflinePlayer islandOwner = plugin.island.getIslandOwner(player);
- if(experiences.containsKey(islandOwner.getName())) {
- Set<OfflinePlayer> members = plugin.island.getIslandMembers(player);
- if(members != null) {
- for(OfflinePlayer member : members) {
- if(member.isOnline() && !member.equals(player)) {
- return;
- }
- }
- }
- if(islandOwner.isOnline()) {
- return;
- }
- experiences.remove(islandOwner.getName());
- }
- if(plugin.scoreBoard.lattyTokens.containsKey(player.getName())) {
- plugin.scoreBoard.lattyTokens.remove(player.getName());
- }
- if(plugin.scoreBoard.levels.containsKey(player.getName())) {
- plugin.scoreBoard.levels.remove(player.getName());
- }
- if(plugin.scoreBoard.moneyAmounts.containsKey(player.getName())) {
- plugin.scoreBoard.moneyAmounts.remove(player.getName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement