Пример #1
0
 public boolean removePower(String pow) {
   Iterator<Power> it = powers.iterator();
   Power power = null;
   while (it.hasNext()) {
     Power p = it.next();
     if (p.getName().equalsIgnoreCase(pow)) {
       it.remove();
       power = p;
       rebuild();
       break;
     }
   }
   if (power != null) {
     if (power instanceof PowerHit) {
       powerHit.remove((PowerHit) power);
     }
     if (power instanceof PowerLeftClick) {
       powerLeftClick.remove(power);
     }
     if (power instanceof PowerRightClick) {
       powerRightClick.remove(power);
     }
     if (power instanceof PowerProjectileHit) {
       powerProjectileHit.remove(power);
     }
     if (power instanceof PowerTick) {
       powerTick.remove(power);
     }
   }
   return power != null;
 }
Пример #2
0
  public void save(ConfigurationSection s) {
    s.set("name", name);
    s.set("id", id);
    s.set("display", displayName.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    s.set("quality", quality.toString());
    s.set("damageMin", damageMin);
    s.set("damageMax", damageMax);
    s.set("armour", armour);
    s.set("type", type.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    s.set("hand", hand.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    s.set("lore", loreText.replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    ArrayList<String> descriptionConv = new ArrayList<String>(description);
    for (int i = 0; i < descriptionConv.size(); i++) {
      descriptionConv.set(i, descriptionConv.get(i).replaceAll("" + ChatColor.COLOR_CHAR, "&"));
    }
    s.set("description", descriptionConv);
    s.set("item", item.getType().toString());
    s.set("ignoreWorldGuard", ignoreWorldGuard);

    ItemMeta meta = localeMeta.get("en_GB");
    if (meta instanceof LeatherArmorMeta) {
      s.set("item_colour", ((LeatherArmorMeta) meta).getColor().asRGB());
    } else {
      s.set("item_data", item.getDurability());
    }
    ConfigurationSection powerConfigs = s.createSection("powers");
    int i = 0;
    for (Power p : powers) {
      MemoryConfiguration pConfig = new MemoryConfiguration();
      pConfig.set("powerName", p.getName());
      p.save(pConfig);
      powerConfigs.set(Integer.toString(i), pConfig);
      i++;
    }

    // Recipes
    s.set("hasRecipe", hasRecipe);
    if (hasRecipe) {
      s.set("recipe", recipe);
    }

    ConfigurationSection drops = s.createSection("dropChances");
    for (String key : dropChances.keySet()) {
      drops.set(key, dropChances.get(key));
    }

    s.set("maxDurability", maxDurability);
    s.set("forceBar", forceBar);
  }
Пример #3
0
 public void addPower(Power power, boolean update) {
   powers.add(power);
   Power.powerUsage.put(power.getName(), Power.powerUsage.get(power.getName()) + 1);
   if (power instanceof PowerHit) {
     powerHit.add((PowerHit) power);
   }
   if (power instanceof PowerLeftClick) {
     powerLeftClick.add((PowerLeftClick) power);
   }
   if (power instanceof PowerRightClick) {
     powerRightClick.add((PowerRightClick) power);
   }
   if (power instanceof PowerProjectileHit) {
     powerProjectileHit.add((PowerProjectileHit) power);
   }
   if (power instanceof PowerTick) {
     powerTick.add((PowerTick) power);
   }
   if (update) rebuild();
 }
Пример #4
0
  public List<String> getTooltipLines(String locale) {
    ArrayList<String> output = new ArrayList<String>();
    int width = 150;
    output.add(encodedID + quality.colour + ChatColor.BOLD + displayName);
    int dWidth = getStringWidthBold(ChatColor.stripColor(displayName));
    if (dWidth > width) width = dWidth;

    dWidth = getStringWidth(ChatColor.stripColor(hand + "     " + type));
    if (dWidth > width) width = dWidth;
    String damageStr;
    if (damageMin == 0 && damageMax == 0 && armour != 0) {
      damageStr = armour + "% " + Plugin.plugin.getConfig().getString("defaults.armour", "Armour");
    } else if (armour == 0 && damageMin == 0 && damageMax == 0) {
      damageStr = null;
    } else if (damageMin == damageMax) {
      damageStr =
          damageMin + " " + Plugin.plugin.getConfig().getString("defaults.damage", "Damage");
    } else {
      damageStr =
          damageMin
              + "-"
              + damageMax
              + " "
              + Plugin.plugin.getConfig().getString("defaults.damage", "Damage");
    }
    if (damageMin != 0 || damageMax != 0 || armour != 0) {
      dWidth = getStringWidth(damageStr);
      if (dWidth > width) width = dWidth;
    }

    for (Power p : powers) {
      dWidth = getStringWidth(ChatColor.stripColor(p.displayText(locale)));
      if (dWidth > width) width = dWidth;
    }

    for (String s : description) {
      dWidth = getStringWidth(ChatColor.stripColor(s));
      if (dWidth > width) width = dWidth;
    }

    tooltipWidth = width;

    output.add(
        ChatColor.WHITE
            + hand
            + StringUtils.repeat(
                " ", (width - getStringWidth(ChatColor.stripColor(hand + type))) / 4)
            + type);
    if (damageStr != null) {
      output.add(ChatColor.WHITE + damageStr);
    }

    for (Power p : powers) {
      output.add(p.displayText(locale));
    }
    if (loreText.length() != 0) {
      int cWidth = 0;
      int tWidth = 0;
      StringBuilder out = new StringBuilder();
      StringBuilder temp = new StringBuilder();
      out.append(ChatColor.YELLOW);
      out.append(ChatColor.ITALIC);
      String currentColour = ChatColor.YELLOW.toString();
      String dMsg = "\"" + loreText + "\"";
      for (int i = 0; i < dMsg.length(); i++) {
        char c = dMsg.charAt(i);
        temp.append(c);
        if (c == ChatColor.COLOR_CHAR || c == '&') {
          i += 1;
          temp.append(dMsg.charAt(i));
          currentColour = ChatColor.COLOR_CHAR + "" + dMsg.charAt(i);
          continue;
        }
        if (c == ' ') tWidth += 4;
        else tWidth += Font.widths[c] + 1;
        if (c == ' ' || i == dMsg.length() - 1) {
          if (cWidth + tWidth > width) {
            cWidth = 0;
            cWidth += tWidth;
            tWidth = 0;
            output.add(out.toString());
            out = new StringBuilder();
            out.append(currentColour);
            out.append(ChatColor.ITALIC);
            out.append(temp);
            temp = new StringBuilder();
          } else {
            out.append(temp);
            temp = new StringBuilder();
            cWidth += tWidth;
            tWidth = 0;
          }
        }
      }
      out.append(temp);
      output.add(out.toString());
    }

    for (String s : description) {
      output.add(s);
    }
    return output;
  }
Пример #5
0
  public RPGItem(ConfigurationSection s) {

    name = s.getString("name");
    id = s.getInt("id");
    setDisplay(s.getString("display"), false);
    setType(
        s.getString("type", Plugin.plugin.getConfig().getString("defaults.sword", "Sword")), false);
    setHand(
        s.getString("hand", Plugin.plugin.getConfig().getString("defaults.hand", "One handed")),
        false);
    setLore(s.getString("lore"), false);
    description = (List<String>) s.getList("description", new ArrayList<String>());
    for (int i = 0; i < description.size(); i++) {
      description.set(i, ChatColor.translateAlternateColorCodes('&', description.get(i)));
    }
    quality = Quality.valueOf(s.getString("quality"));
    damageMin = s.getInt("damageMin");
    damageMax = s.getInt("damageMax");
    armour = s.getInt("armour", 0);
    item = new ItemStack(Material.valueOf(s.getString("item")));
    ItemMeta meta = item.getItemMeta();
    if (meta instanceof LeatherArmorMeta) {
      ((LeatherArmorMeta) meta).setColor(Color.fromRGB(s.getInt("item_colour", 0)));
    } else {
      item.setDurability((short) s.getInt("item_data", 0));
    }
    for (String locale : Locale.getLocales()) {
      localeMeta.put(locale, meta.clone());
    }
    ignoreWorldGuard = s.getBoolean("ignoreWorldGuard", false);

    // Powers
    ConfigurationSection powerList = s.getConfigurationSection("powers");
    if (powerList != null) {
      for (String sectionKey : powerList.getKeys(false)) {
        ConfigurationSection section = powerList.getConfigurationSection(sectionKey);
        try {
          if (!Power.powers.containsKey(section.getString("powerName"))) {
            // Invalid power
            continue;
          }
          Power pow = Power.powers.get(section.getString("powerName")).newInstance();
          pow.init(section);
          pow.item = this;
          addPower(pow, false);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    }
    encodedID = getMCEncodedID(id);

    // Recipes
    hasRecipe = s.getBoolean("hasRecipe", false);
    if (hasRecipe) {
      recipe = (List<ItemStack>) s.getList("recipe");
    }

    ConfigurationSection drops = s.getConfigurationSection("dropChances");
    if (drops != null) {
      for (String key : drops.getKeys(false)) {
        double chance = drops.getDouble(key, 0.0);
        chance = Math.min(chance, 100.0);
        if (chance > 0) {
          dropChances.put(key, chance);
          if (!Events.drops.containsKey(key)) {
            Events.drops.put(key, new HashSet<Integer>());
          }
          Set<Integer> set = Events.drops.get(key);
          set.add(getID());
        } else {
          dropChances.remove(key);
          if (Events.drops.containsKey(key)) {
            Set<Integer> set = Events.drops.get(key);
            set.remove(getID());
          }
        }
        dropChances.put(key, chance);
      }
    }
    if (item.getType().getMaxDurability() != 0) {
      hasBar = true;
    }
    maxDurability = s.getInt("maxDurability", item.getType().getMaxDurability());
    forceBar = s.getBoolean("forceBar", false);

    if (maxDurability == 0) {
      maxDurability = -1;
    }

    rebuild();
  }