Пример #1
0
  public static void transferPotionMeta(PotionMeta meta, JsonObject json, boolean meta2json) {
    if (meta2json) {
      if (!meta.hasCustomEffects()) return;
      json.add(POTION_EFFECTS, convertPotionEffectList(meta.getCustomEffects()));
    } else {
      JsonElement element = json.get(POTION_EFFECTS);
      if (element == null) element = json.get(POTION_EFFECTS_OLD);
      if (element == null) return;

      meta.clearCustomEffects();
      for (PotionEffect pe : convertPotionEffectList(element)) {
        meta.addCustomEffect(pe, false);
      }
    }
  }
Пример #2
0
 public static void transferAuthor(BookMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasTitle()) return;
     json.addProperty(BOOK_AUTHOR, meta.getAuthor());
   } else {
     JsonElement element = json.get(BOOK_AUTHOR);
     if (element == null) return;
     meta.setAuthor(element.getAsString());
   }
 }
Пример #3
0
 public static void transferSkullMeta(SkullMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasOwner()) return;
     json.addProperty(SKULL_OWNER, meta.getOwner());
   } else {
     JsonElement element = json.get(SKULL_OWNER);
     if (element == null) return;
     meta.setOwner(element.getAsString());
   }
 }
Пример #4
0
 public static void transferLore(ItemMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasLore()) return;
     json.add(LORE, convertStringList(meta.getLore()));
   } else {
     JsonElement element = json.get(LORE);
     if (element == null) return;
     meta.setLore(convertStringList(element));
   }
 }
Пример #5
0
 public static void transferName(ItemMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasDisplayName()) return;
     json.addProperty(NAME, meta.getDisplayName());
   } else {
     JsonElement element = json.get(NAME);
     if (element == null) return;
     meta.setDisplayName(element.getAsString());
   }
 }
Пример #6
0
 public static void transferFireworkMetaPower(
     FireworkMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     json.addProperty(FIREWORK_FLIGHT, meta.getPower());
   } else {
     JsonElement element = json.get(FIREWORK_FLIGHT);
     if (element == null) return;
     meta.setPower(element.getAsInt());
   }
 }
Пример #7
0
 public static void transferPages(BookMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasTitle()) return;
     json.add(BOOK_PAGES, convertStringList(meta.getPages()));
   } else {
     JsonElement element = json.get(BOOK_PAGES);
     if (element == null) return;
     meta.setPages(convertStringList(element));
   }
 }
Пример #8
0
 public static void transferCount(ItemStack stack, JsonObject json, boolean stack2json) {
   if (stack2json) {
     int count = stack.getAmount();
     if (count == DEFAULT_COUNT) return;
     json.addProperty(COUNT, count);
   } else {
     JsonElement element = json.get(COUNT);
     if (element == null) return;
     stack.setAmount(element.getAsInt());
   }
 }
Пример #9
0
 public static void transferId(ItemStack stack, JsonObject json, boolean stack2json) {
   if (stack2json) {
     int id = stack.getTypeId();
     if (id == DEFAULT_ID) return;
     json.addProperty(ID, id);
   } else {
     JsonElement element = json.get(ID);
     if (element == null) return;
     stack.setTypeId(element.getAsInt());
   }
 }
Пример #10
0
 public static void transferFireworkEffectMeta(
     FireworkEffectMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasEffect()) return;
     json.add(FIREWORK_EFFECT, FireworkEffectAdapter.toJson(meta.getEffect()));
   } else {
     JsonElement element = json.get(FIREWORK_EFFECT);
     if (element == null) return;
     meta.setEffect(FireworkEffectAdapter.fromJson(element));
   }
 }
Пример #11
0
  public static void transferMapMeta(MapMeta meta, JsonObject json, boolean meta2json) {
    if (meta2json) {
      if (!meta.isScaling()) return;
      json.addProperty(MAP_SCALING, true);
    } else {
      JsonElement element = json.get(MAP_SCALING);
      if (element == null) return;

      meta.setScaling(element.getAsBoolean());
    }
  }
Пример #12
0
 public static void transferDamage(ItemStack stack, JsonObject json, boolean stack2json) {
   // Durability is a weird name since it is the amount of damage.
   if (stack2json) {
     int damage = stack.getDurability();
     if (damage == DEFAULT_DAMAGE) return;
     json.addProperty(DAMAGE, damage);
   } else {
     JsonElement element = json.get(DAMAGE);
     if (element == null) return;
     stack.setDurability(element.getAsShort());
   }
 }
Пример #13
0
 public static void transferFireworkMetaEffects(
     FireworkMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasEffects()) return;
     json.add(FIREWORK_EFFECTS, convertFireworkEffectList(meta.getEffects()));
   } else {
     JsonElement element = json.get(FIREWORK_EFFECTS);
     if (element == null) return;
     meta.clearEffects();
     meta.addEffects(convertFireworkEffectList(element));
   }
 }
Пример #14
0
 public static void transferEnchants(ItemMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasEnchants()) return;
     json.add(ENCHANTS, convertEnchantLevelMap(meta.getEnchants()));
   } else {
     JsonElement element = json.get(ENCHANTS);
     if (element == null) return;
     for (Entry<Enchantment, Integer> entry : convertEnchantLevelMap(element).entrySet()) {
       meta.addEnchant(entry.getKey(), entry.getValue(), true);
     }
   }
 }
Пример #15
0
  public static void transferRepaircost(ItemMeta meta, JsonObject json, boolean meta2json) {
    if (!(meta instanceof Repairable)) return;
    Repairable repairable = (Repairable) meta;

    if (meta2json) {
      if (!repairable.hasRepairCost()) return;
      json.addProperty(REPAIRCOST, repairable.getRepairCost());
    } else {
      JsonElement element = json.get(REPAIRCOST);
      if (element == null) return;

      repairable.setRepairCost(element.getAsInt());
    }
  }
Пример #16
0
  public static void transferLeatherArmorMeta(
      LeatherArmorMeta meta, JsonObject json, boolean meta2json) {
    if (meta2json) {
      Color color = meta.getColor();

      if (Bukkit.getItemFactory().getDefaultLeatherColor().equals(color)) return;

      json.addProperty(LEATHER_ARMOR_COLOR, color.asRGB());
    } else {
      JsonElement element = json.get(LEATHER_ARMOR_COLOR);
      if (element == null) return;
      meta.setColor(Color.fromRGB(element.getAsInt()));
    }
  }
Пример #17
0
 public static void transferEnchantmentStorageMeta(
     EnchantmentStorageMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasStoredEnchants()) return;
     json.add(STORED_ENCHANTS, convertEnchantLevelMap(meta.getStoredEnchants()));
   } else {
     JsonElement element = json.get(STORED_ENCHANTS);
     if (element == null) return;
     // TODO: Add a pull request to get rid of this entry set loop!
     // TODO: A set, clear, remove all system is missing
     for (Entry<Enchantment, Integer> entry : convertEnchantLevelMap(element).entrySet()) {
       meta.addStoredEnchant(entry.getKey(), entry.getValue(), true);
     }
   }
 }