Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cz.dubcat.attributeupgrader;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map.Entry;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.scheduler.BukkitScheduler;
- import cz.dubcat.attributeupgrader.JsonBuilder.HoverAction;
- import cz.dubcat.attributeupgrader.constructors.Combination;
- import cz.dubcat.attributeupgrader.constructors.Gem;
- import cz.dubcat.attributeupgrader.constructors.GemType;
- import cz.dubcat.attributeupgrader.constructors.GlobalLogic;
- import cz.dubcat.attributeupgrader.constructors.McAttribute;
- import cz.dubcat.attributeupgrader.constructors.ReqItem;
- import cz.dubcat.attributeupgrader.constructors.Stat;
- import cz.dubcat.attributeupgrader.constructors.UpgradeLevel;
- import cz.dubcat.attributeupgrader.logic.Conditions;
- import cz.dubcat.attributeupgrader.logic.Executions;
- import cz.dubcat.attributeupgrader.logic.Logic;
- import cz.dubcat.attributeupgrader.logic.LogicAPI;
- public class AuAPI {
- public final String cfg_upgrade = "upgrade.";
- public final String cfg_lang = "lang.";
- public String patr1 = "[-+](\\d+[.,]?\\d?)";
- public String patr2 = "([-+]?)(\\d+[.,]?\\d?)(-)(\\d+[.,]?\\d?)";
- public Pattern single = Pattern.compile(patr1);
- public Pattern doubles = Pattern.compile(patr2);
- public String colorizeText(String string) {
- string = string.replaceAll("&0", ChatColor.BLACK + "");
- string = string.replaceAll("&1", ChatColor.DARK_BLUE + "");
- string = string.replaceAll("&2", ChatColor.DARK_GREEN + "");
- string = string.replaceAll("&3", ChatColor.DARK_AQUA + "");
- string = string.replaceAll("&4", ChatColor.DARK_RED + "");
- string = string.replaceAll("&5", ChatColor.DARK_PURPLE + "");
- string = string.replaceAll("&6", ChatColor.GOLD + "");
- string = string.replaceAll("&7", ChatColor.GRAY + "");
- string = string.replaceAll("&8", ChatColor.DARK_GRAY + "");
- string = string.replaceAll("&9", ChatColor.BLUE + "");
- string = string.replaceAll("&a", ChatColor.GREEN + "");
- string = string.replaceAll("&b", ChatColor.AQUA + "");
- string = string.replaceAll("&c", ChatColor.RED + "");
- string = string.replaceAll("&d", ChatColor.LIGHT_PURPLE + "");
- string = string.replaceAll("&e", ChatColor.YELLOW + "");
- string = string.replaceAll("&f", ChatColor.WHITE + "");
- string = string.replaceAll("&l", ChatColor.BOLD + "");
- string = string.replaceAll("&r", ChatColor.WHITE + "");
- return string;
- }
- public String stripColours(String string) {
- string = string.replaceAll(ChatColor.BLACK + "", "");
- string = string.replaceAll(ChatColor.DARK_BLUE + "", "");
- string = string.replaceAll(ChatColor.DARK_GREEN + "", "");
- string = string.replaceAll(ChatColor.DARK_AQUA + "", "");
- string = string.replaceAll(ChatColor.DARK_RED + "", "");
- string = string.replaceAll(ChatColor.DARK_PURPLE + "", "");
- string = string.replaceAll(ChatColor.GOLD + "", "");
- string = string.replaceAll(ChatColor.GRAY + "", "");
- string = string.replaceAll(ChatColor.DARK_GRAY + "", "");
- string = string.replaceAll(ChatColor.BLUE + "", "");
- string = string.replaceAll(ChatColor.GREEN + "", "");
- string = string.replaceAll(ChatColor.AQUA + "", "");
- string = string.replaceAll(ChatColor.RED + "", "");
- string = string.replaceAll(ChatColor.LIGHT_PURPLE + "", "");
- string = string.replaceAll(ChatColor.YELLOW + "", "");
- string = string.replaceAll(ChatColor.WHITE + "", "");
- string = string.replaceAll(ChatColor.BOLD + "", "");
- string = string.replaceAll(ChatColor.WHITE + "", "");
- return string;
- }
- public boolean sendMessage(Player p, String message) {
- p.sendMessage(colorizeText(Main.getPlugin().getConfig().getString(cfg_lang + "prefix") + message));
- return true;
- }
- public FileConfiguration getConfig() {
- return Main.getPlugin().getConfig();
- }
- public int getTimeAnim() {
- int i = 0;
- for (String key : getConfig().getConfigurationSection(cfg_upgrade + "animation").getKeys(false)) {
- i = getConfig().getInt( cfg_upgrade + "animation." + key + ".delay");
- }
- i = i + 2;
- return i;
- }
- public boolean isValidItem(Player p, ItemStack item) {
- if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().hasLore()) {
- sendMessage(p, getConfig().getString(cfg_lang + "notsupported"));
- return false;
- }
- return true;
- }
- public boolean checkPermissionToUpgrade(Player p){
- String permission = getConfig().getString(cfg_upgrade + "premission.perm");
- if(getConfig().getBoolean(cfg_upgrade + "premission.use") && !p.hasPermission(permission)){
- sendMessage(p, getConfig().getString(cfg_lang + "noperm"));
- return false;
- }
- return true;
- }
- public void reloadGems(){
- Main.gems.clear();
- for(String gem : getConfig().getConfigurationSection("gems.gems").getKeys(true)){
- Main.gems.add(new Gem(gem));
- }
- }
- public void reloadCombinations(){
- if(Main.combinations.size() != 0)
- Main.combinations.clear();
- for(String combination : getConfig().getConfigurationSection(cfg_upgrade + "cost_combinations").getKeys(false)){
- double currency = getConfig().getDouble(cfg_upgrade + "cost_combinations." + combination + ".curency");
- Main.combinations.add(new Combination(currency, combination));
- }
- }
- public void reloadLoadedStats(){
- HashMap<String, Stat> stats = new HashMap<String, Stat>();
- if(Main.stats != null && Main.stats.size() != 0)
- Main.stats.clear();
- for(String stat : getConfig().getConfigurationSection(cfg_upgrade + "stats").getKeys(false)){
- double per_level = getConfig().getDouble(cfg_upgrade + "stats." + stat + ".perlevel");
- String name;
- String format;
- Boolean cast;
- boolean custom = true;
- if(!stat.contains("DEFAULT_MC")){
- name = colorizeText(getConfig().getString(cfg_upgrade + "stats." + stat + ".name"));
- format = colorizeText(getConfig().getString(cfg_upgrade + "stats." + stat + ".format"));
- cast = getConfig().getBoolean(cfg_upgrade + "stats." + stat + ".casttoint");
- }else{
- name = stat;
- format = "";
- cast = false;
- custom = false;
- }
- Stat stat_cfg = new Stat(stat, per_level, name, format, cast, custom);
- stats.put(stat, stat_cfg);
- }
- Main.stats = stats;
- }
- public void reloadWeaponLevels(){
- if(Main.levels.size() != 0)
- Main.levels.clear();
- int i = 0;
- for(@SuppressWarnings("unused") String level : getConfig().getConfigurationSection(cfg_upgrade + "levels").getKeys(false)){
- Main.levels.add(new UpgradeLevel(i));
- i++;
- }
- }
- public void reloadGlobalLogic(){
- Main.global_logic = new GlobalLogic();
- }
- public UpgradeLevel getLevel(int i){
- return Main.levels.get(i);
- }
- public HashMap<String, Stat> getLoadedStats(){
- return Main.stats;
- }
- public ArrayList<Combination> getCombinations(){
- return Main.combinations;
- }
- public int getCapUpgradeLevel(){
- return Main.levels.size()-1;
- }
- public GlobalLogic getGlobalLogic(){
- return Main.global_logic;
- }
- public ArrayList<Gem> getGems(){
- return Main.gems;
- }
- public int getMaxAllowedGems(){
- return getConfig().getInt("gems.maxgems");
- }
- public double getBonusChance(Player p){
- double bonus_val = 0;
- for(String bonus : getConfig().getConfigurationSection(cfg_upgrade + "permission.bonus").getKeys(false)){
- if(p.hasPermission(getConfig().getString(cfg_upgrade + "permission.bonus." + bonus + ".permission"))){
- bonus_val += getConfig().getDouble(cfg_upgrade + "permission.bonus." + bonus + ".percentage");
- p.sendMessage("Bonus chance of " + (getConfig().getDouble(cfg_upgrade + "permission.bonus." + bonus + ".percentage") *100));
- }
- }
- return bonus_val;
- }
- public boolean forceDowngradeItem(ItemStack item, Player p){
- return true;
- }
- public boolean forceUpgradeItem(ItemStack item, Player p){
- return true;
- }
- public void insertGem(Player p, ItemStack item, ItemStack gem_item, Gem gem){
- AttributeApi api = Main.getApi();
- int global_gems = api.getGemsNumInWeapon(item, GemType.GLOBAL, gem);
- int internal_gems = api.getGemsNumInWeapon(item, GemType.LOCAL, gem);
- if(global_gems >= getMaxAllowedGems() || internal_gems >= gem.levels.size()){
- p.sendMessage("You have reach max amount of gems in one item.");
- return;
- }
- int amount = gem_item.getAmount();
- if(amount > gem.amount){
- gem_item.setAmount(amount - gem.amount);
- p.getInventory().addItem(gem_item);
- }
- List<String> lore_gem = gem_item.getItemMeta().getLore();
- List<String> new_lore = new ArrayList<String>();
- ItemMeta meta = item.getItemMeta();
- if(item.getItemMeta().hasLore())
- new_lore = item.getItemMeta().getLore();
- if(getConfig().getBoolean("gems.devider.enabled"))
- new_lore.add(colorizeText(getConfig().getString("gems.devider.value")));
- new_lore.addAll(lore_gem);
- meta.setLore(new_lore);
- if(gem.format){
- String item_name = item.getItemMeta().getDisplayName();
- if(internal_gems != 0){
- String[] split = item_name.split(" ");
- String waht_to_find = gem.levels.get(internal_gems).format;
- for(int i = 0 ; i < split.length; i++){
- String sp = split[i];
- if(sp.contains(waht_to_find)){
- split[i] = gem.levels.get(internal_gems+1).format;
- break;
- }
- }
- String new_name = "";
- for(int i = 0 ; i < split.length; i++){
- if(i != 0)
- new_name += " ";
- new_name += split[i];
- }
- meta.setDisplayName(colorizeText(new_name));
- }else{
- meta.setDisplayName(colorizeText(item_name + " " + gem.levels.get(internal_gems+1).format));
- }
- }
- item.setItemMeta(meta);
- item = api.setGems(item, internal_gems, gem);
- p.getInventory().addItem(item);
- p.sendMessage("You have successfuully inserted gem!");
- }
- public void upgrade(ItemStack item, int cur_level, Player p){
- AttributeApi api = Main.getApi();
- Combination comb = hasAnyCombination(p);
- if(comb == null){
- p.sendMessage("doung combination");
- return;
- }
- if(!item.equals(api.getHoldingItem(p))){
- sendMessage(p, getConfig().getString(cfg_lang + "sameweapon"));
- return;
- }
- //ny how much upgrade will occur
- int upgrade_by_level = comb.getUpgradeByNumber();
- //if cur_weapon_level + upgradeby > cap then this
- if(cur_level + upgrade_by_level > getCapUpgradeLevel())
- upgrade_by_level = getCapUpgradeLevel() - cur_level;
- UpgradeLevel cur_upgrade_level = getLevel(cur_level);
- UpgradeLevel new_upgrade_level = getLevel(cur_level + upgrade_by_level);
- //totalchance
- double chance = new_upgrade_level.getChance() + getBonusChance(p);
- //takemoney
- if(comb.money != 0)
- Main.economy.withdrawPlayer(p, comb.money);
- //take items
- if(comb.items != null || comb.items.size() != 0){
- for(ItemStack pitem : p.getInventory().getContents()){
- if(pitem == null || pitem.getType() == Material.AIR || !pitem.hasItemMeta() || !pitem.getItemMeta().hasDisplayName())
- continue;
- inner : for(ReqItem citem : comb.items){
- String display_name = pitem.getItemMeta().getDisplayName();
- Material mat = pitem.getType();
- if(citem.name.equals(display_name) && mat == citem.type){
- int amount = pitem.getAmount() - citem.amount;
- if(amount > 0)
- pitem.setAmount(amount);
- else
- p.getInventory().remove(item);
- p.updateInventory();
- continue inner;
- }
- }
- }
- }
- ItemMeta meta = item.getItemMeta();
- List<String> lore = item.getItemMeta().getLore();
- //on success
- if(chance > 1 || Math.random() < chance){
- for(Entry<String, Stat> s : getLoadedStats().entrySet()){
- lore = changeStatValue(lore, s.getValue(), upgrade_by_level*s.getValue().per_level_upgrade);
- }
- meta.setLore(lore);
- String display_name = item.getItemMeta().getDisplayName();
- //check if format is enabled
- if(getConfig().getBoolean(cfg_upgrade + "format.enabled")){
- if(cur_level == 0){
- display_name += " "+colorizeText(new_upgrade_level.colour + getConfig().getString(cfg_upgrade + "format.format").replace("%number%", new_upgrade_level.level+""));
- }else{
- String[] split = display_name.split(" ");
- String uprade_format = getConfig().getString(cfg_upgrade + "format.format").replace("%number%", cur_upgrade_level.level+"");
- for(int i = 0; i < split.length; i ++)
- {
- if(split[i].contains(uprade_format))
- {
- split[i] = colorizeText(new_upgrade_level.colour + getConfig().getString(cfg_upgrade + "format.format").replace("%number%", new_upgrade_level.level+""));
- break;
- }
- }
- String new_name = "";
- for(int i = 0; i < split.length; i ++)
- {
- if(i != 0)
- new_name += " ";
- new_name += split[i];
- }
- display_name = new_name;
- }
- meta.setDisplayName(display_name);
- }
- item.setItemMeta(meta);
- ItemStack new_item = api.setItemLevel(item, new_upgrade_level.level);
- for(Entry<String, Stat> stat : getLoadedStats().entrySet()){
- Stat stats = stat.getValue();
- if(stats.name.contains("DEFAULT_MC_")){
- String stat_name = stats.name;
- if(stat_name.contains("DAMAGE") || stat_name.contains("DMG")){
- new_item = api.increaseAttribute(new_item, McAttribute.DAMAGE, upgrade_by_level*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("HEALTH") || stat_name.contains("HP")){
- new_item = api.increaseAttribute(new_item, McAttribute.HEALTH, upgrade_by_level*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("SPEED")){
- new_item = api.increaseAttribute(new_item, McAttribute.SPEED, upgrade_by_level*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("ATTACK_SPEED")){
- new_item = api.increaseAttribute(new_item, McAttribute.ATTACK_SPEED, upgrade_by_level*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("ARMOR")){
- new_item = api.increaseAttribute(new_item, McAttribute.ARMOR, upgrade_by_level*stats.per_level_upgrade);
- continue;
- }
- }
- }
- new_item = applyLogic(p, new_item,new_upgrade_level,cur_upgrade_level, new_upgrade_level, true);
- p.getInventory().setItemInMainHand(new_item);
- p.updateInventory();
- api.particles(p);
- if(getConfig().getBoolean("upgrade.broadcast.enabled")){
- if(new_upgrade_level.level >= getConfig().getInt("upgrade.broadcast.minlevel"))
- sendRawMsg(lore, p, new_upgrade_level.colour, new_upgrade_level.level, display_name);
- }
- }else{
- //downgrade
- //ny how much upgrade will occur
- int downgradeby = new_upgrade_level.getDowngrade();
- if(cur_level - downgradeby < 0)
- downgradeby = downgradeby - cur_level;
- UpgradeLevel new_downgrade_level;
- if(downgradeby != 0)
- new_downgrade_level = getLevel(cur_level - downgradeby);
- else
- new_downgrade_level = getLevel(cur_level);
- if(downgradeby != 0){
- for(Entry<String, Stat> s : getLoadedStats().entrySet()){
- lore = changeStatValue(lore, s.getValue(), downgradeby*s.getValue().per_level_upgrade*-1);
- }
- meta.setLore(lore);
- //displayname
- String display_name = item.getItemMeta().getDisplayName();
- if(getConfig().getBoolean(cfg_upgrade + "format.enabled")){
- if(cur_level > 0){
- String[] split = display_name.split(" ");
- String uprade_format = getConfig().getString(cfg_upgrade + "format.format").replace("%number%", cur_level+"");
- for(int i = 0; i < split.length; i ++){
- if(split[i].contains(uprade_format)){
- if(new_downgrade_level.level == 0)
- split[i] = "";
- else
- split[i] = colorizeText(new_downgrade_level.colour + getConfig().getString(cfg_upgrade + "format.format").replace("%number%", new_downgrade_level.level+""));
- break;
- }
- }
- String new_name = "";
- for(int i = 0; i < split.length; i ++){
- if(i != 0)
- new_name += " ";
- new_name += split[i];
- }
- display_name = new_name;
- }
- meta.setDisplayName(display_name);
- }
- item.setItemMeta(meta);
- item = api.setItemLevel(item, new_downgrade_level.level);
- for(Entry<String, Stat> stat : getLoadedStats().entrySet()){
- Stat stats = stat.getValue();
- if(stats.name.contains("DEFAULT_MC_")){
- String stat_name = stats.name;
- if(stat_name.contains("DAMAGE") || stat_name.contains("DMG")){
- item = api.decreaseAttribute(item, McAttribute.DAMAGE, downgradeby*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("HEALTH") || stat_name.contains("HP")){
- item = api.decreaseAttribute(item, McAttribute.HEALTH, downgradeby*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("SPEED")){
- item = api.decreaseAttribute(item, McAttribute.SPEED, downgradeby*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("ATTACK_SPEED")){
- item = api.decreaseAttribute(item, McAttribute.ATTACK_SPEED, downgradeby*stats.per_level_upgrade);
- continue;
- }else if(stat_name.contains("ARMOR")){
- item = api.decreaseAttribute(item, McAttribute.ARMOR, downgradeby*stats.per_level_upgrade);
- continue;
- }
- }
- }
- }
- item = applyLogic(p, item,new_upgrade_level,cur_upgrade_level, new_downgrade_level, false);
- p.getInventory().setItemInMainHand(item);
- p.updateInventory();
- }
- }
- public Combination hasAnyCombination(Player p){
- PlayerInventory inv = p.getInventory();
- ArrayList<Combination> combs = getCombinations();
- for(int i = 0; i < combs.size(); i++){
- Combination comb = combs.get(i);
- ArrayList<ItemStack> found = new ArrayList<ItemStack>();
- if(!comb.enabled)
- continue;
- if(comb.money != 0 && !Main.economy.has(p, comb.money))
- continue;
- for(ItemStack item : inv.getContents()){
- if(item==null || item.getType() == Material.AIR)
- continue;
- if(!item.hasItemMeta() || !item.getItemMeta().hasDisplayName())
- continue;
- if(comb.items != null || comb.items.size() != 0){
- for(ReqItem rqitem : comb.items){
- if(item.getType() == rqitem.type && item.getAmount() >= rqitem.amount && item.getItemMeta().getDisplayName().equals(rqitem.name)){
- found.add(item);
- }
- }
- }
- if(found.size() == comb.items.size())
- return comb;
- }
- }
- return null;
- }
- @SuppressWarnings("unchecked")
- public ItemStack applyLogic(Player p,ItemStack item, UpgradeLevel upgrade_level_logic, UpgradeLevel level, UpgradeLevel new_level , boolean upgrade){
- ArrayList<Logic> logic;
- LogicAPI logic_api = new LogicAPI();
- if(upgrade)
- logic = (ArrayList<Logic>) upgrade_level_logic.conditions_upgrade.clone();
- else
- logic = (ArrayList<Logic>) upgrade_level_logic.conditions_downgrade.clone();
- GlobalLogic global = getGlobalLogic();
- if(upgrade)
- logic.addAll(global.conditions_upgrade);
- else
- logic.addAll(global.conditions_downgrade);
- boolean lastcond = true;
- String lastcondkey = "nothing";
- for(Iterator<Logic> iterator = logic.iterator(); iterator.hasNext();){
- Logic log = iterator.next();
- if(log.isCondition){
- Conditions cond = log.cond;
- String key = log.content;
- if(log.name.contains(lastcondkey) && !lastcond)
- continue;
- lastcondkey = log.name;
- String[] split = key.split(" ");
- if(cond == Conditions.EQUALS || cond == Conditions.GREATER || cond == Conditions.SMALLER){
- String firstparam = split[0];
- String secparam = split[2];
- System.out.println(log.content +" Name: " + log.name);
- System.out.println("First param: " + firstparam + " Sec param: "+secparam );
- double firstnum = 0,secnum=0;
- if(logic_api.checkIfRandom(firstparam)){
- firstnum = logic_api.getRandomNumber();
- }else if(logic_api.checkIfRandom(secparam)){
- secnum = logic_api.getRandomNumber();
- }
- if(upgrade){
- if(logic_api.checkStringForUpgrade(firstparam)){
- firstnum = (double) (new_level.level - level.level);
- }else if(logic_api.checkStringForUpgrade(secparam)){
- secnum = (double) (new_level.level - level.level);
- }
- }else{
- if(logic_api.checkStringForDownpgrade(firstparam)){
- firstnum = (double) (level.level - new_level.level);
- }else if(logic_api.checkStringForDownpgrade(secparam)){
- secnum = (double) (level.level - new_level.level);
- }
- }
- if(logic_api.isNumeric(firstparam)){
- firstnum = (double)Double.parseDouble(firstparam);
- }else if(logic_api.isNumeric(secparam)){
- secnum = (double)Double.parseDouble(secparam);
- System.out.println("Sec param"+secparam);
- }
- if(logic_api.isStat(firstparam) != null){
- Stat stat = logic_api.isStat(firstparam);
- firstnum = getStatValue(item, stat);
- }else if(logic_api.isStat(secparam) != null){
- Stat stat = logic_api.isStat(secparam);
- secnum = getStatValue(item, stat);
- }
- if(cond == Conditions.EQUALS){
- System.out.println(cond + "");
- if(firstnum != secnum){
- lastcond = false;
- }
- }else if(cond == Conditions.SMALLER){
- System.out.println(cond + "");
- if(firstnum > secnum || firstnum ==secnum ){
- lastcond = false;
- }
- }else if(cond == Conditions.GREATER){
- System.out.println(cond + " " + firstnum +" > " + secnum);
- if(firstnum < secnum || firstnum ==secnum ){
- lastcond = false;
- }
- }
- }else if(cond == Conditions.ITEM_TYPE){
- System.out.println(cond + "");
- Material mat = Material.valueOf(split[2]);
- if(mat != item.getType())
- lastcond = false;
- }else if(cond == Conditions.ELSE){
- System.out.println(cond + "");
- if( lastcond == false)
- lastcond = true;
- else
- lastcond = false;
- }
- continue;
- }
- if((log.name.contains(lastcondkey) && lastcond) || !log.name.contains(lastcondkey)){
- System.out.println("Exectuions name : " + log.name + " Last condition key :" + lastcondkey);
- Executions exec = log.exec;
- String content = log.content;
- if(exec == Executions.MESSAGE){
- logic_api.sendMessage(p, content
- .replaceAll("%weapon_name%", (item.getItemMeta().hasDisplayName()) ? item.getItemMeta().getDisplayName() : item.getType() + "")
- .replaceAll("%old_level%", level.level+"")
- .replaceAll("%new_level%", new_level.level+"")
- .replaceAll("%level%", new_level.level+""));
- continue;
- }else if(exec == Executions.SOUND){
- p.playSound(p.getLocation(), Sound.valueOf(content), 1f,1f);
- continue;
- }else if(exec == Executions.BROADCAST){
- Bukkit.getServer().broadcastMessage(colorizeText(content
- .replaceAll("%weapon_name%", (item.getItemMeta().hasDisplayName()) ? item.getItemMeta().getDisplayName() : item.getType() + "")
- .replaceAll("%old_level%", level.level+"")
- .replaceAll("%new_level%", new_level.level+"")
- .replaceAll("%level%", new_level.level+"")));
- continue;
- }else if(exec == Executions.REMOVEITEM){
- item = new ItemStack(Material.AIR);
- continue;
- }else if(exec == Executions.STOP){
- return item;
- }else if(exec == Executions.EXEC){
- if(content.contains("addto")){
- String[] split = content.split(" ");
- Stat stat = logic_api.getStat(split[1]);
- if(stat == null)
- continue;
- double add = Double.valueOf(logic_api.calculateFromString(item, split[2]));
- ItemMeta meta = item.getItemMeta();
- List<String> lore = item.getItemMeta().getLore();
- lore = changeStatValue(lore, stat, add);
- meta.setLore(lore);
- item.setItemMeta(meta);
- continue;
- }else if(content.contains("removefrom")){
- String[] split = content.split(" ");
- Stat stat = logic_api.getStat(split[1]);
- if(stat== null)
- continue;
- double add = Double.valueOf(logic_api.calculateFromString(item, split[2])) * -1;
- ItemMeta meta = item.getItemMeta();
- List<String> lore = item.getItemMeta().getLore();
- lore = changeStatValue(lore, stat, add);
- meta.setLore(lore);
- item.setItemMeta(meta);
- continue;
- }else if(content.contains("setstat")){
- String[] split = content.split(" ");
- Stat stat = logic_api.getStat(split[1]);
- if(stat== null)
- continue;
- double newval = Double.valueOf(logic_api.calculateFromString(item, split[2]));
- if(stat.cast_to_int)
- newval = (int) newval;
- ItemMeta meta = item.getItemMeta();
- List<String> lore = item.getItemMeta().getLore();
- for(int i = 0; i < lore.size(); i++){
- String line = lore.get(i);
- if(line.contains(stat.name)){
- lore.set(i, colorizeText(stat.format.replace("%value%", newval+"")));
- }
- }
- meta.setLore(lore);
- item.setItemMeta(meta);
- continue;
- }
- }
- }else{
- continue;
- }
- }
- return item;
- }
- public List<String> changeStatValue(List<String> lore, Stat stat, double change){
- for(int i = 0; i < lore.size(); i++){
- String line = lore.get(i);
- if(line.contains(stat.name)){
- String[] linesplit = line.split(" ");
- String[] formatsplit = stat.format.split(" ");
- String stat_string = "";
- for(int y = 0; y < formatsplit.length; y++){
- if(formatsplit[y].contains("%value%")){
- stat_string = stripColours(linesplit[y]);
- }
- }
- Matcher match1 = single.matcher(stat_string);
- Matcher match2 = doubles.matcher(stat_string);
- System.out.println("Found stat " + stat_string);
- if(match1.find()){
- double stat_value = Double.parseDouble(match1.group(1)) + change;
- System.out.println("Matched ");
- if(stat.cast_to_int)
- stat_value = (int) stat_value;
- System.out.println(stat_value);
- lore.set(i, colorizeText(stat.format.replace("%value%", stat_value+"")));
- return lore;
- }else if ( match2.find()){
- double stat_value1 = Double.parseDouble(match2.group(2)) + change;
- double stat_value2 = Double.parseDouble(match2.group(4)) + change;
- if(stat.cast_to_int){
- stat_value1= (int) stat_value1;
- stat_value2 = (int) stat_value2;
- }
- lore.set(i, colorizeText(stat.format.replace("%value%", stat_value1+"-"+stat_value2)));
- return lore;
- }
- }
- }
- return lore;
- }
- public double getStatValue(ItemStack item, Stat stat){
- List<String> lore = item.getItemMeta().getLore();
- for(String str : lore){
- if(str.contains(stat.name)){
- String[] linesplit = str.split(" ");
- String[] formatsplit = stat.format.split(" ");
- String stat_string = "";
- for(int y = 0; y < formatsplit.length; y++){
- if(formatsplit[y].contains("%value%")){
- stat_string = stripColours(linesplit[y]);
- }
- }
- Matcher match1 = single.matcher(stat_string);
- Matcher match2 = doubles.matcher(stat_string);
- Double stat_value = 0D;
- if(match1.find()){
- stat_value = Double.parseDouble(match1.group(1));
- }else if(match2.find()){
- stat_value = Double.parseDouble(match2.group(4));
- }
- /*double cur_value = 0;
- Matcher m = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(str);
- if (m.find()) {
- cur_value = Double.parseDouble(m.group(1));
- }*/
- return stat_value;
- }
- }
- return 0;
- }
- public void sendRawMsg(List<String> lore, Player player, String colour, int newlevel, String name) {
- String msg = Main.getPlugin().getConfig().getString("lang.success");
- msg = msg.replaceAll("%player%", player.getDisplayName());
- msg = msg.replaceAll("%upgrade%",
- colour + Main.getPlugin().getConfig().getString("upgrade.format.format").replace("%number%", newlevel + ""));
- JsonBuilder jb;
- String rawmsg = name + "\n";
- int i = 0;
- for (String l : lore) {
- if (i == (lore.size() - 1))
- rawmsg = rawmsg + l;
- else
- rawmsg = rawmsg + l + "\n";
- i++;
- }
- jb = new JsonBuilder().withText(colorizeText(msg)).withHoverEvent(HoverAction.SHOW_TEXT, colorizeText(rawmsg));
- jb.toString();
- for (Player p : Bukkit.getOnlinePlayers()) {
- Main.getApi().sendJson(p);
- }
- JsonBuilder.extras.clear();
- }
- public void runAnim(final Player player){
- BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
- AttributeApi api = Main.getApi();
- for(final String key : getConfig().getConfigurationSection("upgrade.animation").getKeys(false)){
- scheduler.scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
- @Override
- public void run() {
- if(!getConfig().getString("upgrade.animation."+key+".sound").equals(""))
- player.playSound(player.getLocation(), Sound.valueOf(getConfig().getString("upgrade.animation."+key+".sound")), 2F, 1F);
- if(!getConfig().getString("upgrade.animation."+key+".output").equals("")) {
- api.sendAction(player, getConfig().getString("upgrade.animation."+key+".output"));
- }
- if(!getConfig().getString("upgrade.animation."+key+".chat").equals(""))
- player.sendMessage(colorizeText(getConfig().getString("upgrade.animation."+key+".chat")));
- }
- }, getConfig().getInt("upgrade.animation."+key+".delay"));
- }
- }
- @Deprecated
- public int getItemLevel(ItemStack item){
- if(item == null){
- return 0;
- }else{
- List<String> itemlore = item.getItemMeta().getLore();
- int level = -1;
- for(String s: itemlore){
- level++;
- if (s.contains("Level:")){
- String levelraw = itemlore.get(level);
- String[] splitlevel = levelraw.split(" ");
- level = Integer.parseInt(stripColours(splitlevel[1].replaceAll("ยง2", "")));
- break;
- }
- }
- return level;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement